铁轨上的红宝石——Link_to不知怎么破坏了我的路线



我正在尝试在我的web应用程序中使用link_to

<% if @statuses %>
  <% @statuses.each do |status| %>
    <div class="well">
      <%= status.content %>
      <br></br>
      <% @profile_user = User.find(status.tag_list).first %>
      <%= @profile_user%>
      <%= link_to @profile_user.profile_name, user_profile_url(@profile_user) %>
      <br></br>
      <%= status.user.full_name %>
      <hr />
      <%= link_to time_ago_in_words(status.created_at), status_path(status) %> ago
    </div>
  <% end %>
<% end%>

这行代码导致错误:

<%= link_to @profile_user.profile_name, user_profile_url(@profile_user) %>

我得到的错误是:

undefined method `profile_name' for nil:NilClass

但我的路线似乎是可行的。路由应为:mywebsite.com/profile_name

我的当前代码出现错误。如果我删除了有问题的行,我可以手动输入我试图访问的URL,页面将毫无问题地呈现。

以下代码有点奇怪:

User.find(status.tag_list)

find方法将查找具有匹配id的用户,您确定状态对象上的方法tag_list将返回用户id吗?

最新更新