0

与这个人有类似的问题:带有 has_scope 的 Rails 4:静默失败

但他的回答对我的情况没有帮助。我正在使用带有以下代码的 has_scope gem:

#model
class Inbox < ActiveRecord::Base
  has_paper_trail
  has_many :requests
  belongs_to :match_rule
  scope :by_person, -> person { where(Request.where(inbox_id: params[:id]).person[:first_name] => person) }
end

#controller
class InboxesController < ApplicationController
  before_action :authorize
  before_action :set_inbox, only: [:show, :edit, :update, :destroy]
  before_filter :set_paper_trail_whodunnit
  has_scope :by_person

def show
  @requests = apply_scopes(Request.where(inbox_id: params[:id]).paginate(:page => params[:page], :per_page => 20))
end

private
  def set_inbox
    @inbox = Inbox.find(params[:id])
  end

然后使用 url http://localhost:3000/inboxes/3?by_person=Meghan我得到这个错误

undefined method `by_person' for #<Request::ActiveRecord_Relation:0x007fadf72a3148>

对于这条线

@requests = apply_scopes(Request.where(inbox_id: params[:id]).paginate(:page => params[:page], :per_page => 20))

一旦我得到它与名字一起使用,我将继续处理所有其他要过滤的东西。在这种情况下,我感谢任何帮助或指导!

4

0 回答 0