2009-11-19 43 views
0

我有以下的路線設置:命名路線及的link_to問題

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" 

我想使用的link_to函數的視圖頁面像:

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

這給了我這個錯誤,我不知道我做錯了:

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

回答

1

圍繞(:format)的括號正在拋棄您的路由。你需要這樣做在parens?如果刪除它們,並改變map.person線一樣,那麼你將被罰款:

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

在這種情況下的link_to因爲你擁有它會正常工作。

+0

謝謝,這是一個非常愚蠢的錯誤,就像一個魅力。 – efleming

0

我相信你的鏈接應該是這樣的:

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