Reputation: 6695
I'm trying to get my application to show the url as follows: example.com/42/jessica-alba This is my current routes line(not sure if it's correct)
match '/:id/:name' => 'models#show'
For some reason if I type example.com/42/gvkodjgj030 it'll still shw me the user with the id 42, regardless of the text after the /
Another thing I'm trying to accomplish is to get the link_to tags of the user to point to example.com/42/jessica-alba instead of example.com/users/42
Please help me out guys, this is my first rails app :)
*EDIT: the first part is actually working with the snippet I've pasted, I still need to fix the 2nd part though.
Upvotes: 2
Views: 2353
Reputation: 11552
in your routes.rb
`match '/:id/:name' => 'models#show', :as => :show_model'
in your models/show.html.erb code,
<%=link_to "Show", show_model_path(:id => 2, :name => "some name")
does that work?
Upvotes: 3
Reputation: 138200
This is because all routing does is determine which action should handle the request. It doesn't do any of the processing.
Look in your ModelsController
at the show
action, and you'll see that the lookup is probably only using the params[:id]
- if you want the lookup to depend on the params[:name]
then the action is where you should change it.
Upvotes: 3