Stack Exchange
js.erb file not getting triggered
I have three files:
Controller: 
   def index
    @filterrific = initialize_filterrific(
      DimDictionary,
      params[:filterrific],
      select_options: {},
      persistence_id: 'shared_key',
      default_filter_params: {},
      available_filters: [ :dictionary_word_filter ]
    ) || return

    @dictionaries = @filterrific.find.limit(30)

    respond_to do |format|
      format.html
      format.js
    end
  end

Index.html.haml
= form_for_filterrific @filterrific do |f|
  .ui.form
    .fields
      .field
        Filter Word
        = f.text_field :dictionary_word_filter
  = render_filterrific_spinner
= render(partial: '/test/list', locals: { dictionaries: @dictionaries })

Index.js.erb
<% alert("hi"); %>
<% console.log('working Mannnnn') %>
<%  js = escape_javascript(render(partial: '/test/list', locals: { dictionaries: @dictionaries })) %>
$("#filterrific_results").html("<%= js %>");

The Index.js.erb is not getting triggered. Every time the page loads, its should run the Index.js.erb and show the alert and the console.log and the show the html right? Or the js.erb will only trigger on ajax request?
I am here using filterrific gem for filtration purpose but the index.js.erb file never gets triggered.
Even i have includes the js format in my controller. How should it be ? am i doing something wrong?


Every time the page loads, its should run the Index.js.erb and show
  the alert and the console.log and the show the html right?

No, format.js means, that your controller returns JS in response, when client wants to JS.
You should use remote:true for example, if you want to JS in responnse. There is no possibility to render both, because controller action can only repond to one HTTP request at a time.
More about responses in Rails:
https://api.rubyonrails.org/classes/ActionController/MimeResponds.html
And about javascript in Rails:
https://guides.rubyonrails.org/working_with_javascript_in_rails.html

So if you read http://filterrific.clearcove.ca/pages/example_application.html this gems documentation. They are triggering a ajax call to your controller and then the erb automatically updates the list but the problem is that everytime i do some action the gem form never triggered a call to my backendd

So, your problem concerns configuration of gem probably. Any logs with error from console?

There are no error's, like none.
I have previously used this gem for other project but i am facing problems with this now. I have configured everything correctly and it still dosent seems to work. Maybe you can check this out https://stackoverflow.com/questions/54416093/filterrific-not-filtering-data

You can look at filterrific demo source code: https://github.com/jhund/filterrific_demo and compare your code. Check wheater you attach filterrific/filterrific-jquery to your application.js
