Filterrific 和多租户,限制 Active Record 结果

Filterrific and Multitenancy, Limiting Active Record Results

我正在尝试将 filterrific 搜索的结果限制为仅具有给定 client_id.

的实例

我的设置如下:

# customers_controller.rb
@filterrific = initialize_filterrific(
    Customer,
    params[:filterrific],
    select_options: {
      sorted_by: Customer.options_for_sorted_by,
      with_agent_id: Agent.options_for_select
    },
  ) or return

有没有办法限制返回的活动记录结果,比如Customer.where('client_id', 2) ?

你可以这样做:

@filterrific = initialize_filterrific(
    Customer,
    params[:filterrific],
    select_options: {
      sorted_by: Customer.options_for_sorted_by,
      with_agent_id: Agent.options_for_select
    },
  ) or return
       @customers = @filterrific.find.where(client_id: 2).paginate(:page => params[:page], :per_page => 10) # add paginate if you require pagination

我想我真的明白了。看起来您只是将 FIND 传递给@filterrific 定义...

@appointments = @filterrific.find.where(vendor_id: @vendor_locations.select(:vendor_id))
.page(params[:page])