Ruby on rails Rails最佳位置gem不更新订单表

Ruby on rails Rails最佳位置gem不更新订单表,ruby-on-rails,best-in-place,Ruby On Rails,Best In Place,我正在构建一个市场应用程序。卖家可以列出要销售的产品。我正在使用best_in_place允许卖家在其销售页面中输入跟踪号码和运输承运人名称 我在另一个模型中也使用了best_in_place,效果很好。由于某种原因,订单表更新似乎不起作用。以下是我得到的错误: NoMethodError in Orders#sales undefined method `tracking' for nil:NilClass 错误指向下面使用的最佳位置的第一行 这是我的视图-显示卖家列表和两列,用于输入跟踪和

我正在构建一个市场应用程序。卖家可以列出要销售的产品。我正在使用best_in_place允许卖家在其销售页面中输入跟踪号码和运输承运人名称

我在另一个模型中也使用了best_in_place,效果很好。由于某种原因,订单表更新似乎不起作用。以下是我得到的错误:

NoMethodError in Orders#sales
undefined method `tracking' for nil:NilClass
错误指向下面使用的最佳位置的第一行

这是我的视图-显示卖家列表和两列,用于输入跟踪和运营商名称:

<div class="center">
  <h2>Sales History for <%= current_user.name %></h2>
</div>

<% if user_signed_in? %>
   <%= link_to 'Add New Listing', new_listing_path, class: "btn btn-link", data: {  no_turbolink: true } %>
<% end %>

<table class="table table-striped table-bordered">
  <tr>
    <th class="col-md-2">Image</th>
    <th class="col-md-2">Item</th>
    <th class="col-md-1">Price</th>
    <th class="col-md-2">Customer</th>
    <th class="col-md-2">Date Sold</th>
    <th class="col-md-2">Shipment Tracking #</th>
    <th class="col-md-1">Carrier (UPS, USPS, etc.)</th>
 </tr>

<% @orders.each do |order| %>
<tr>
  <td><%= image_tag order.listing.image.url(:thumb) %></td>
  <td><%= order.listing.name %></td>
  <td><%= number_to_currency(order.listing.price) %></td>
  <td><%= order.buyer.name %></td>
  <td><%= order.created_at.strftime("%B %-d, %Y") %></td>
  <td><%= best_in_place @order, :tracking, :type => :input %></td>
  <td><%= best_in_place @order, :carrier, :type => :input %></td>
</tr>
<% end %>
</table>
这是我的控制器的销售方法和更新方法

class OrdersController < ApplicationController
  before_action :set_order, only: [:show, :edit, :update, :destroy]
  before_action :authenticate_user! 
  before_action :check_user, only: [:edit, :update]    

def sales
   @orders = Order.all.where(seller: current_user).order("created_at DESC")
end

def update
  @order = Order.find(params[:id])
  @order.update_attributes(params[:order])
end

def check_user
  if current_user.id != @seller && current_user.name != "admin admin"
    redirect_to root_url, alert: "Sorry, you are not the seller of this listing"
  end
end

试着把它全部说清楚,看看它是否有效:

<%= best_in_place @order, :tracking, :type => :input, :path => {:controller => :sales, :action => :update, :id => order.id} %>
基本上我只是把@order换成了order

<% @orders.each do |order| %>
<tr>
  <td><%= image_tag order.listing.image.url(:thumb) %></td>
  <td><%= order.listing.name %></td>
  <td><%= number_to_currency(order.listing.price) %></td>
  <td><%= order.buyer.name %></td>
  <td><%= order.created_at.strftime("%B %-d, %Y") %></td>
  <td><%= best_in_place order, :tracking, :type => :input %></td>
  <td><%= best_in_place order, :carrier, :type => :input %></td>
</tr>
<% end %>