简体   繁体   中英

Fixed sort with Filterrific

I am implementing Filterrific in Rails 5, but do not require a sort function. Instead, I am trying to set a specific sort criteria that will not change, so no sort field on view, or option select. I am struggling to get it to recognise the scope change that I have made. Any help greatly appreciated...

The error I get is generated by the controller:

"Invalid default filter params: ["sorted_by"]"

Model:

scope :sorted_by, lambda { |sort_option|
  case sort_option
  when /^date_desc/
    order("account_xactions.xaction_date desc")
  end
}

filterrific(
  default_filter_params: { sorted_by: 'date_desc' },
  available_filters: [
    :search_query,
    :with_account_id
  ]
)

Controller:

@filterrific = initialize_filterrific(
  AccountXaction,
  params[:filterrific],
  :select_options => {
    with_account_id: Account.options_for_select
    }
) or return
@account_xactions = @filterrific

What were you thinking Lloydo...

You forgot to add the scope into the available_filters section and furthermore, you didn't add the find method for the call to filterrific in the controller.

filterrific(
  default_filter_params: { sorted_by: 'date_desc' },
  available_filters: [
    :sorted_by,
    :search_query,
    :with_account_id
  ]
)

Call in controller:

@account_xactions = @filterrific.find

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM