I’m having a really strange issue with named helpers. So let’s start off with the routes in question:
resources :subjects, path: 'library' do
resources :modules, controller: 'subject_modules'
end
Where Subjects#to_param returns self.slug. Now, for a subject named “Foo” and module with id 1, where the subject is @subject and module is m:
link_to subject_modules_path(@subject, m)gives /library/foo/modules.1link_to edit_subject_module_path(@subject, m)gives /library/foo/modules/1/editlink_to mgives /library/1/modules/physics
As for link_to [@subject, m], I get:
Routing Error
No route matches {:action=>"show", :controller=>"subject_modules", :subject_id=>#<Subject id: 2, name: "Foo", created_at: "2011-12-30 02:00:38", updated_at: "2011-12-30 02:00:38", slug: "foo">, :id=>#<SubjectModule ---snipped--->}
Does anyone know why the routes are broken the way they are, and what I could possibly do to fix this?
EDIT:
Rake routes:
subject_modules GET /library/:subject_id/modules(.:format) {:action=>"index", :controller=>"subject_modules"}
POST /library/:subject_id/modules(.:format) {:action=>"create", :controller=>"subject_modules"}
new_subject_module GET /library/:subject_id/modules/new(.:format) {:action=>"new", :controller=>"subject_modules"}
edit_subject_module GET /library/:subject_id/modules/:id/edit(.:format) {:action=>"edit", :controller=>"subject_modules"}
subject_module GET /library/:subject_id/modules/:id(.:format) {:action=>"show", :controller=>"subject_modules"}
PUT /library/:subject_id/modules/:id(.:format) {:action=>"update", :controller=>"subject_modules"}
DELETE /library/:subject_id/modules/:id(.:format) {:action=>"destroy", :controller=>"subject_modules"}
There appears to be some quirk in Rails’ routing system currently.
Using
subject_module_path(@subject, m)initially caused a “can’t find route” error for me (which I tried at the time I wrote the question), but it somehow worked eventually.I can’t pinpoint this issue so unfortunately I have no idea of its cause. This problem happened with Rails 3.1.3.