views:

111

answers:

1

So I've created an action, lets call it 'raise' in the controller 'elevator'. 'elevator' is nested in 'building'.

What routes should I create, or what link_to url can I make so

/buldings/2/elevators/4/raise will work?

Thanks, Elliot

+3  A: 

If you really want to nest them like that, here's the route. You didn't specify a Rails version, so this is something that will work with recent versions, as opposed to just in 2.3+.

map.resources :buildings do |buildings|
  buildings.resources :elevators, :member => {:up => :put}
end

Note the name change for your action. Please don't name an action "raise." That's a method in Kernel. You're going to give someone an aneurism when they try to debug your code.

You'll end up with a path helper that looks like this.

up_building_elevator_path(:building_id => 2, :elevator_id => 4)

After setting up the routes, you can see all of the routes available to your elevators by running:

rake -T | grep elevator
jdl