views:

36

answers:

2

The following code:

map.resources :users, :has_many => :items

Could be written like this in a block:

map.resources :users do |user|
   user.resources :items
end

How could I write the following code in a block?

map.resources :users, :member => { :start => :post }

Also, where could I find documentation on writing routes in blocks? The Routes Documentation does not seem to show it.

Thank you!

+3  A: 

Rails 2.x doesn't allow you to use blocks for member definition. With Rails 3.x you can write

resources :users do
  member do
    post :start  
  end
end
Simone Carletti
+1  A: 

You can do it like so in Rails 2 (2.3.5 is the version I tested it on):

map.resources :users, :member => { :start => :post } do |user|   
   user.resources :items   
end   

From here: http://www.engineyard.com/blog/2010/the-lowdown-on-routes-in-rails-3/

dwhite