Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reset Filterrific Filters on Page Re-load

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?

like image 824
Jackson Cunningham Avatar asked Jun 22 '15 17:06

Jackson Cunningham


1 Answers

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.

like image 193
Jo Hund Avatar answered Oct 30 '22 23:10

Jo Hund