I’m stuck on a routing problem within a Rails 3.0.x application.
What I’m trying to achieve is a URL like /registration/renew/1 . The idea is that this would renew registration for a member with id = 1.
So to that end I setup the following routes
routes.rb
match "registration/renew" => "registration#renew"
The user arrives at the registration page via a navigation link such as
<%= link_to "Full Member", registration_renew_path(@member) %>
The problem is that the generated link comes out like: /registration/renew.1 which indicates that the :format extension is being created and appended. Which then I tried to make optional via inclusion of a responder argument :format as per the following matching rule
match "registration/renew(/:id(.:format))" => "registration#new"
but this fails with
No route matches {:controller=>"registration", :action=>"renew", :format=>#<Member id: 1,.....
So at this point I rechecked the Rails Guides etc but still couldn’t get to generate the URL I was after.
Only when I had the two rules:
match "registration/renew" => "registration#renew"
match "registration(/:action(/:id(.:format)))" => "registration#renew"
in the routes file would the URL /registration/renew/1 get me to the page. Although I didn’t feel that this was the correct, tidy solution.
The final question(s)
- What should be the link_to method
- What is the correct routes.rb entry
Thanks in Advance
You just need pass args explicitly and define the name of this route
With only id
With id and format
Without id
You don’t need the route without params in your example.