Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/56.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
Html 轨道问题-未定义方法';名称';_Html_Ruby On Rails_Ruby - Fatal编程技术网

Html 轨道问题-未定义方法';名称';

Html 轨道问题-未定义方法';名称';,html,ruby-on-rails,ruby,Html,Ruby On Rails,Ruby,由于某些原因,此页面无法使用RubyonRails5打开。它为nil:NilClass错误提供了一个未定义的方法'name' 上次我打开代码时,代码运行得很好。有人能帮忙吗?非常感谢 这里是查看页面 <h1> Your sale history page </h1> <table class="table table-bordered table-hover table-striped"> <tr> <th>Image&

由于某些原因,此页面无法使用RubyonRails5打开。它为nil:NilClass错误提供了一个未定义的方法'name'

上次我打开代码时,代码运行得很好。有人能帮忙吗?非常感谢

这里是查看页面

<h1> Your sale history page </h1>
  <table class="table table-bordered table-hover table-striped">
  <tr>
    <th>Image</th>
    <th>Title</th>
    <th>Label</th>
    <th>Condition</th>
    <th>Customer</th>
    <th>Price</th>
    <th>Date Sold</th>
  </tr>

    <% @orders.each do |order| %>
    <tr>
      <td><%= image_tag order.record.image.url(:thumb)%></td>
      <td><%= order.record.Title %></td>
      <td><%= order.record.Label %></td>
      <td><%= order.record.Condition %></td>
      <td><%= order.buyer.name %></td>
      <td><%= order.record.Selling_Price %> </td>
      <%#THE BELOW CODE IS FOR RUBY DATE. FOUND ON rubydoc%>
       <td><%= order.created_at.strftime("%-d %B, %Y") %></td>
       <td>

    </tr>
<%end%>
您的销售历史记录页面
形象
标题
标签
条件
顾客
价格
售出日期

class用户
好的,我想你需要快速修复

   <td><%= order.try(&:buyer).try(&:name) %></td>


这将确保您不会在没有买家的情况下出错,因为您可以看到witch order没有买家

好的,我想您需要快速修复

   <td><%= order.try(&:buyer).try(&:name) %></td>


这将确保在没有买家的情况下,您不会收到错误,除非查看“witch order is without buyer”

是否所有记录上都有
订单
表中的
买家id

可能存在
buyer\u id
为空的记录。
或者,
订单
无法获取
买家
,因为没有匹配的id。

订单表是否在所有记录上都有
买家id

可能存在
buyer\u id
为空的记录。
或者,
订单
无法获得
买家
,因为没有匹配的id。

我发现下面的链接非常有用,可以了解更多关于“try”用法的信息,以及为什么在上述场景中“try”优于“rescue nil”选项


我发现下面的链接有助于了解更多关于“try”用法的信息,以及为什么在上述场景中“try”优于“rescue nil”选项


看起来像是
订单。买家
返回
nil
(而不是返回
买家
实例)。发生这种情况的原因可能有很多。您确定每个
订单
都有一个与之相关的
买家吗?是的,他们与表相关。昨天这个工作做得很好。我不知道为什么它现在导致了一个错误!请发布
订单
买家
型号的相关部分,好吗?看起来像是
订单。买家
正在返回
nil
(而不是返回
买家
实例)。发生这种情况的原因可能有很多。您确定每个
订单
都有一个与之相关的
买家吗?是的,他们与表相关。昨天这个工作做得很好。我不知道为什么它现在导致了一个错误!请您发布
订单
买家
型号的相关部分,好吗?非常感谢,这已经解决了问题!也许有一件物品与我删除的帐户有关?很高兴我能帮助大家:)非常感谢,这解决了问题!也许其中一件售出的物品与我删除的帐户有关?很高兴我能帮助大家:)