Rails:在注释中重定向到用户的个人资料

时间:2014-10-30 21:53:52

标签: ruby-on-rails comments associations acts-as-commentable

我的rails应用程序中有一个非常简单的评论系统 - 我想允许用户在评论者名称上输入他的个人资料。

但没有任何成功 - 我不确定我错过了什么。

<% @comments.each do |comment| %>

          <p><a href="<%= user_path(@comment.user_id) %>" style="text-decoration : none"><%= image_tag comment.user.image, class: "img-circle", width: "30x30" if comment.user %><font class="small" color="#28c3ab"> @<%= comment.user.name if comment.user %></font></a> 

<% end %>

但我没有路线匹配错误:

No route matches {:action=>"show", :controller=>"users", :id=>nil} missing required keys: [:id]

我缺少什么想法?我知道这很容易,但我现在已经没想到了。我应该在控制器中添加此调用的位置?

2 个答案:

答案 0 :(得分:1)

我发现您的问题可能是@comment

变化:

user_path(@comment.user_id)

为:

user_path(comment.user_id)

答案 1 :(得分:0)

检查@comment.user_id的值。可能没有为实例分配user_id,值为nil

相关问题