Reset Filterrific Filters on Page Re-load

2.4k views Asked by At

I'm using the great filterrific plugin by ClearCove.

I want to reset the filters when a page gets re-loaded. Currently, it's keeping the last search filter saved which is confusing IMO.

Here's my controller:

  def index
     @filterrific = initialize_filterrific(
      current_user.patients,
      params[:filterrific],
      :select_options => {
        sorted_by: Patient.options_for_sorted_by      },
    ) or return
    @patients = @filterrific.find.page(params[:page])
    @templates = Template.all
    gon.root_url = root_url
  end

I could do this the hack-y way which would be to use Jquery to click the reset_filterrific_url which is rendered in the view. But that seems wrong. How do I clear the filters whenever page is loaded?

1

There are 1 answers

1
Jo Hund On BEST ANSWER

filterrific params are persisted in the browser session. You can disable session persistence by adding the persistence_id option:

@filterrific = initialize_filterrific(
  current_user.patients,
  params[:filterrific],
  :select_options => {
    sorted_by: Patient.options_for_sorted_by      
  },
  :persistence_id => false,
) or return

More info at the filterrific documentation.