views:

87

answers:

2

I have the following routes set up:

map.people 'people(.:format)', :conditions => { :method => :get }, :controller=>"people", :action=>"index"
map.connect 'people(.:format)', :conditions => { :method => :post }, :controller=>"people", :action=>"create"
map.new_person 'people/new(.:format)', :conditions => { :method => :get }, :controller=>"people", :action=>"new"
map.edit_person 'people/:shortname/edit(.:format)', :conditions => { :method => :get }, :controller => 'people', :action => 'edit'
map.person 'people/:shortname(.:format)', :conditions => { :method => :get }, :controller=>"people", :action=>"show"
map.connect 'people/:shortname(.:format)', :conditions => { :method => :put }, :controller=>"people", :action=>"update"
map.connect 'people/:shortname(.:format)', :conditions => { :method => :delete }, :controller=>"people", :action=>"destroy"

I am trying to use the link_to function on a view page like:

<%= link_to 'Show', person_path(person.shortname) %>

This gives me this error and I am not sure what I am doing wrong:

person_url failed to generate from {:controller=>"people", :shortname=>"efleming", :action=>"show"}, expected: {:controller=>"people", :action=>"show"}, diff: {:shortname=>"efleming"}
A: 

I believe your link should look like this:

<%= link_to 'Show', person_path(:shortname => person.shortname) %>
Pär Wieslander
+1  A: 

The parentheses around the (:format) are throwing off your routing. Do you need that to be in parens? If you remove them, and change the map.person line like so then you will be fine:

map.person 'people/:shortname.:format', :conditions => { :method => :get }, :controller=>"people", :action=>"show"

In this case the link_to as you have it will work fine.

bantic
Thanks, that was a pretty dumb mistake, works like a charm.
efleming