0

我的 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]

有什么我想念的想法吗?我知道这很容易,但我现在没有想法。我应该在我的控制器中的哪里添加这个调用?

4

2 回答 2

1

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

改变:

user_path(@comment.user_id)

至:

user_path(comment.user_id)
于 2014-10-30T21:57:06.500 回答
0

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

于 2014-10-30T22:00:25.747 回答