【发布时间】:2014-08-16 07:58:56
【问题描述】:
我正在构建一个市场应用程序,我正在尝试使用 Best in Place gem 来允许卖家为他们的每个订单添加一个跟踪号。
我得到一个我无法解决的 NoMethodError。
NoMethodError in Orders#sales
undefined method `tracking' for nil:NilClass
错误指向视图页面下方的最佳位置线。此视图页面基于方法 Sales(在下面的控制器中),我在其中过滤该特定卖家的订单。
这是我的带有订单路由的 routes.rb。由于不需要编辑或销毁订单,因此我没有创建编辑或删除路线。
resources :listings do
resources :orders, only: [:new, :create, :update]
collection { post :import }
end
这是来自我的订单控制器的 sn-p
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.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
这是我的查看页面:
<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>
在这个问题上停留了一段时间。感谢您对此的任何帮助。
【问题讨论】:
标签: ruby-on-rails erb rails-routing best-in-place