开发者

Named Routes & link_to problem

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 =&g开发者_Go百科t; '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"}


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.


I believe your link should look like this:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜