module Filterrific
  class Engine < ::Rails::Engine

    # It's an engine so that we can add javascript and image assets
    # to the asset pipeline.

    isolate_namespace Filterrific

    require 'filterrific/param_set'

    initializer "filterrific" do |app|

      ActiveSupport.on_load :active_record do
        require 'filterrific/active_record_extension'
        class ::ActiveRecord::Base
          extend Filterrific::ActiveRecordExtension::ClassMethods
        end
      end

      ActiveSupport.on_load :action_view do
        require 'filterrific/action_view_extension'
        class ::ActionView::Base
          include Filterrific::ActionViewExtension
        end
      end

      app.config.assets.precompile += %w(filterrific-spinner.gif)

    end

  end
end

require 'filterrific/param_set'
require 'filterrific/action_view_extension'
require 'filterrific/active_record_extension'

module Filterrific
  class Engine < ::Rails::Engine

    # It's an engine so that we can add javascript and image assets
    # to the asset pipeline.

    isolate_namespace Filterrific

    ActiveSupport.on_load :active_record do
      extend Filterrific::ActiveRecordExtension
    end

    ActiveSupport.on_load :action_view do
      include Filterrific::ActionViewExtension
    end

    initializer "filterrific" do |app|
      app.config.assets.precompile += %w(filterrific-spinner.gif)
    end

  end
end

Change how we load code: Need to extend ActiveRecord outside of initializer block.
Change how we load code: Need to extend ActiveRecord outside of initializer block. 

Otherwise we get exceptions when another library tries to load a class that uses filterrific. `filterrific` won't be known yet and raises an exception.