views:

1406

answers:

3

Here's the routes.rb:

map.resources :assignments, :shallow => true  do |assignment|  
    assignment.resources :problems  
end

How do i get the url to edit a problem (/assignments/xyz/problems/abc/edit), in code? I have tried both
edit_assignment_problem_path(assignment,problem)
and edit_problem_path(problem).
While the first one works on my local setup, on server it says that method edit_assignment_problem_path is not defined. Any ideas?

+6  A: 

Run this at your command line:

rake routes

It will tell you all the routes that you have defined, and how they map. Very handy.

Squeegy
A: 

Also check out the routing guide that could teach you a lot of new things.

Ryan Bigg
That link is broken. The routing guide can now be found at http://guides.rubyonrails.org/routing.html
chiborg
+2  A: 

:shallow => true was introduced in Rails 2.2. Your local setup probably was running an earlier version while your server probably runs 2.2 or earlier version.

With shallow routes, you MUST specify the full route (e.g. /assignments/a/problems/.. ) for :index, :create, and :new actions (because these actions need the complete path) and MUST use the short route (e.g. /problems/..) for :edit, :show, :update, and :destroy actions.

If you want both full and short versions of all routes the only possibility is to use a nested resource route without shallow plus a short route e.g.:

map.resources :assignments, has_many => :problems
map.resources :problems

Note that in your example you did not need to use the block form for map.resources.

Jean Vincent