NoMethodError未定义的方法是什么?为零:NilClass

时间:2017-01-23 20:07:08

标签: ruby-on-rails ruby

我正在尝试创建一个根据销售情况收集产品数据的报告。我在我的haml中收到一条错误消息,我似乎无法追查。

错误:NoMethodError undefined method任何?'为零:NilClass`

控制器:

class Admin::SalesController < Admin::Controller
  def index
    results = Search.admin_search_orders(params)
    @results = SalesAdminViewModel.new(results, params)
  end

  def show
    product = Product.find_by_number(params[:id])
    @product = SalesViewModel.new(product)
  end
end

视图模型:

  def products
    return @products if defined?(@products)

    models = Catalog::Product.find_ordered(map(&:catalog_id))
    view_models = SalesAdminViewModel.wrap(models)

    @products = PagedArray.from(view_models, page, per_page, total)
  end

  def sorts
    @sorts ||= Search.product_sorts.map do |sort|
      [sort.name, sort.slug]
    end
  end

Html.haml:

%h1 Product Sales

  - if @products.any?

    .mp-browse.mp-cf
      - if @products.num_pages > 1
        = render 'admin/shared/pagination', collection: @products

0 个答案:

没有答案