Rails 如何 link 给 post 或评论的作者?
Rails how to link to the author of a post or a review?
link_to review.author_id, profile_path(review.author_id)
Returns 没有路由匹配 {:action=>"show", :controller=>"profiles", :id=>nil} 缺少必需的键:[:id]
这是因为 review.author_id 正确显示了 author_id。但是当作为参数传递给 profile_path.
时它确实有效
将其更改为#review.author_id 并不能修复错误
在我网站的另一个模块中运行完美
link_to "View Profile", profile_path(@story.user_id)
我想这可能是因为用户是 class,而作者不是,我可以将 author_id 作为整数或索引直接传递给 profile_path 吗?
反正我解决了
link_to review.author_id, profile_path(review.author_id.to_i) %>
编辑:
显然 review.author_id 导致 profile_path 将它解释为一个对象,而 to_s 告诉它把 review.author_id 作为一个值。
其中profile_path也可以作为参数
link_to review.author_id, profile_path(review.author_id)
Returns 没有路由匹配 {:action=>"show", :controller=>"profiles", :id=>nil} 缺少必需的键:[:id]
这是因为 review.author_id 正确显示了 author_id。但是当作为参数传递给 profile_path.
时它确实有效将其更改为#review.author_id 并不能修复错误
在我网站的另一个模块中运行完美
link_to "View Profile", profile_path(@story.user_id)
我想这可能是因为用户是 class,而作者不是,我可以将 author_id 作为整数或索引直接传递给 profile_path 吗?
反正我解决了
link_to review.author_id, profile_path(review.author_id.to_i) %>
编辑:
显然 review.author_id 导致 profile_path 将它解释为一个对象,而 to_s 告诉它把 review.author_id 作为一个值。
其中profile_path也可以作为参数