I am using the Filterrific gem to try to add filtering on an ActiveRecord object for one page only.
In the filterrific page, it says to add this line to application.js
//= require filterrific/filterrific-jquery
From what I read about the asset pipeline, this will add filterrific on all my pages. I can't have this filterrific js in the asset pipeline because it is interfering with previous written javascript on many other pages. Something in filterrific is messing up the rest of the javascript.
So to bypass this, I need to use content_for
but I'm having problems making it work with javascript tag methods for a particular controller rendered page. This is what I've tried so far in my html/haml file in question.
%h1 Signed Certificates
= form_for_filterrific @filterrific do |f|
%div
Sorted by
\#{f.select(:sorted_by, @filterrific.select_options[:sorted_by])}
%div
= link_to('Reset filters', reset_filterrific_url)
= render_filterrific_spinner
#filterrific_results
%div
= page_entries_info @signed_certificates # provided by will_paginate
%table
%tr
%th Common Name
%th Effective Date
%th Expiration Date
- @signed_certificates.each do |sc|
%tr
%td= sc.common_name
%td= sc.effective_date.strftime("%m/%d/%y %H:%M:%S")
%td= sc.expiration_date.strftime("%m/%d/%y %H:%M:%S")
= will_paginate @signed_certificates
At the top I've tried this:
-content_for :javascript =require filterrific/filterrific-jquery
-content_for :javascript 'filterrific/filterrific-jquery'
-content_for :head do
= javascript_include_tag 'filterrific/filterrific-jquery'
Also, I'm reading about this solution here Stackoverflow rails 3.1 but I dont think this is applicable to rails 4.2. If someone knows how to implement conditional javascript from a gem, could you please point out what I'm doing wrong?