Reputation: 25959
In my routs.rb I have the following lines
CyberTrackRails3::Application.routes.draw do
scope "(:locale)", :locale => /en|de|nl/ do
resources :transfusion do
get 'detail', :on => :collection
end
end
end
Next line
url_for( :controller => :transfusion, :action => :detail,
:id => bloodselection[:id]
gets mapped to /nl/transfusion/detail?id=162106
How do I map it to /nl/transfusion/162106 so that controller understands it as id being 162106?
Upvotes: 0
Views: 48
Reputation: 14973
The Rails routing engine pluralizes collections by default, so if you want the defaults to work out of the box, you should use the plural, transfusions
Then instead of url_for
, you could use transfusion_path
to get /nl/transfusions/12345
If you insist on using the singular form in the URL, you can override the path segment as
resources :transfusions, path: "transfusion" do …
which would let you get /nl/transfusion/12345
instead.
Upvotes: 1
Reputation: 10146
That happens because you are setting the detail action on collection, to follow your url structure, it needs to be defined on member.
ie,
CyberTrackRails3::Application.routes.draw do
scope "(:locale)", :locale => /en|de|nl/ do
resources :transfusion do
get 'detail', :on => :member
end
end
end
Upvotes: 2