Getting Started with Rails 3

Rails 3 will be released pretty soon, and right now Rails version 3.0.0.beta4 is already being used in a bunch of projects, so I figured I'd make a little post that would help people get up and running with Rails 3 faster.

Before Rails 3 Rails 3
rails script/server rails s
rails script/generate rails g
rails script/console rails c
respond_to do |format| respond_with(@post)

at the top of the class define the response formats:
respond_to :html, :xml

Post.all(:conditions => { :name => "Getting Started with Rails 3" } Post.where(:name => "Getting Started with Rails 3"
Post.all(:order => "name", :limit => 5) Post.order('posts.name DESC').limit(5)
named_scope :featured, :conditions => { :featured => true } scope :featured, where(:featured => true)
map.root :controller => 'posts', :action => 'index' root :to => 'posts#index'
map.connect '/all_posts', :controller => 'posts', :action => 'index' match '/all_posts', :to => 'posts#index'
map.login '/login', :controller => 'sessions', :action => 'new' match '/login', :to => 'sessions#new', :as => 'login'
map.resources :posts do |post|
    post.resources :comments
end
resources :posts do
    resources :comments
end
<%= render :partial => 'post', :collection => @posts %> <%= render @posts %>

Importing products from Magento into Spree

Magento is a great piece of software, but in my experience using it, everyone who touched it - both me and my client - became so confused after doing so, that the project was delayed for weeks as we mentally and physically recovered from our encounter with..."Magento". This great beast meant us no harm (or did it?), but we never crossed paths with it again, for fear of additional confusion, as well as sudden death. After looking for an easier, less dangerous solution, I found Spree. Easy to use, looks purty out of the box, and built on Ruby on Rails. And there's a Heroku extension. Awesome. 

One problem: The Magento installation had 88 products, with names, descriptions, SKUs, and other fun attributes. Spree has no built-in import or export function.

After some googling, I found a Google group discussion, took some of the example code, tailored it to the CSV format of a standard Magento export, and ended up with this ugly hack:

If you don't have the FasterCSV gem installed, install it before running this import script: 

gem install fastercsv

Use the Rails runner to run this script so it has access to the database: 

script/runner import.rb

and you're done.