Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 路由问题,rails生成错误的url_Ruby On Rails_Ruby - Fatal编程技术网

Ruby on rails 路由问题,rails生成错误的url

Ruby on rails 路由问题,rails生成错误的url,ruby-on-rails,ruby,Ruby On Rails,Ruby,首先,感恩节快乐 所以我的问题是我的路由,我不清楚为什么id param实际上包含整个对象。Rails给了我这个错误: user_url failed to generate from {:action=>"show", :controller=>"users", :id=>#<User id: 19, username: "Dr. Dorothy Buckridge", email: "kyra@hansenstehr.ca", crypted_password: ni

首先,感恩节快乐

所以我的问题是我的路由,我不清楚为什么id param实际上包含整个对象。Rails给了我这个错误:

user_url failed to generate from {:action=>"show", :controller=>"users", :id=>#<User id: 19, username: "Dr. Dorothy Buckridge", email: "kyra@hansenstehr.ca", 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: "kyra@hansenstehr.ca", 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>}

无法真正了解问题所在。

您是否覆盖了用户模型或其继承的任何类中的参数

您可以使用以下命令强制id:

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

这是一个粗略的猜测,但我在键入map.resource:user而不是map.resources:users in the routes.rb时遇到了类似的问题


否则,请针对EmFi的naswer进行验证。

感恩节——不管是什么意思——可能与编程无关。真正的感恩节是近2个月前的事了。跟上时代。谢谢你。。解决了这个问题。
def index
  @recipes = Recipe.search params[:search], :field_weights => { :name => 20, :description => 10 }
end
 <%= link_to recipe.user.username, user_url(recipe.user.id), :class => "user" %>