2009-11-26 23 views
0

首先,感恩節快樂。路由問題,rails生成錯誤的url

所以我的問題是我的路線,我不清楚爲什麼ID參數實際上包含整個對象。 Rails的給了我這個錯誤:

user_url failed to generate from {:action=>"show", :controller=>"users", :id=>#<User id: 19, username: "Dr. Dorothy Buckridge", email: "[email protected]", crypted_password: nil, password_salt: nil, persistence_token: nil, created_at: "2009-11-10 19:38:31", updated_at: "2009-11-10 19:38:31", perishable_token: "", color: nil>}, expected: {:action=>"show", :controller=>"users"}, diff: {:id=>#<User id: 19, username: "Dr. Dorothy Buckridge", email: "[email protected]", crypted_password: nil, password_salt: nil, persistence_token: nil, created_at: "2009-11-10 19:38:31", updated_at: "2009-11-10 19:38:31", perishable_token: "", color: nil>} 

在這條線上出現的錯誤:

<%= link_to recipe.user.username, recipe.user, :class => "user" %> 

任何想法?它似乎應該只是爲該屬性生成對象的id

我的問題控制器:

def index 
    @recipes = Recipe.search params[:search], :field_weights => { :name => 20, :description => 10 } 
end 

實在看不出是什麼問題。

+0

感恩節(不管是什麼意思)可能與編程無關。 – pavium 2009-11-26 20:10:53

+0

真正的感恩節是近2個月前。與時俱進。 – EmFi 2009-11-26 20:14:40

回答

5

您覆蓋用戶模型中的to_params或它繼承的任何類嗎?

您可以強制ID與此:

<%= link_to recipe.user.username, user_url(recipe.user.id), :class => "user" %> 
+0

感謝EmFi ..解決了這個問題。 – useranon 2012-02-03 08:52:17

2

這是胡亂猜測,但我有我的routes.rb

類型map.resource :user,而不是map.resources :users類似的問題,否則驗證對EMFI的鼻子。

+0

這不是這種情況,但檢查的好主意,謝謝! – 2009-11-26 20:55:51