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 :commentsend
|
resources :posts doresources :commentsend
|
<%= render :partial => 'post', :collection => @posts %> |
<%= render @posts %> |