Ransack未定义的方法`空?'

时间:2017-04-09 03:31:33

标签: ruby-on-rails ruby ruby-on-rails-3

我试图从商店获得一系列反馈,但

使用搜索和搜索以及来自反馈的comment_cont和日志显示:

ActionView::Template::Error (undefined method `empty?' for #<Feedback:0x007f189a8fb330>)

有人知道为什么会这样吗?

路线是:

resources :shops, only: [:new, :create, :edit, :update, :show] do

post '/:id/feedbacks', to: 'shops#feedbacks', as: :search_feedbacks
post '/:id/products', to: 'shops#products', as: :search_products

#on shops controller

def feedbacks
  begin
    @shop = Shop.cached_find(params[:id])
  rescue
    @shop = nil
  end

  unless @shop.nil?    
    # @feedbacks = Feedback.by_participant(@vitrine.user, Feedback::FROM_BUYERS).paginate(:per_page => 22, :page => params[:page]).order('created_at DESC')
    @q = Feedback.by_participant(@vitrine.user, Feedback::FROM_BUYERS).ransack(params[:q])
    @feedbacks = @q.result(distinct: true).paginate(page: params[:page], per_page: 22)
    @average_rating_from_buyers = Feedback.average_rating(@vitrine.user, Feedback::FROM_BUYERS)
  end

end

1 个答案:

答案 0 :(得分:0)

我不是在计算机上测试这个,但是distinct: true是否可能导致单个结果返回到paginate,这可能是期待数组或关系?