# Used to ensure that Rails 3.0.x, as well as Rails >= 3.1 with asset pipeline disabled
# get the minified version of the scripts included into the layout in production.
module Jquery
  module Rails

    class Railtie < ::Rails::Railtie
      if config.action_view.javascript_expansions
        config.before_configuration do

          if ::Rails.root.join("public/javascripts/jquery-ui.min.js").exist?
            jq_defaults = %w(jquery jquery-ui)
            jq_defaults.map!{|a| a + ".min" } if ::Rails.env.production? || ::Rails.env.test?
          else
            jq_defaults = ::Rails.env.production? || ::Rails.env.test? ? %w(jquery.min) : %w(jquery)
          end

          # Merge the jQuery scripts, remove the Prototype defaults and finally add 'jquery_ujs'
          # at the end, because load order is important
          config.action_view.javascript_expansions[:defaults] -= PROTOTYPE_JS + ['rails']
          config.action_view.javascript_expansions[:defaults] |= jq_defaults + ['jquery_ujs']
        end
      end
    end

  end
end

# Used to ensure that Rails 3.0.x, as well as Rails >= 3.1 with asset pipeline disabled
# get the minified version of the scripts included into the layout in production.
module Jquery
  module Rails
    class Railtie < ::Rails::Railtie
      config.before_configuration do
        if config.action_view.javascript_expansions
          if ::Rails.root.join("public/javascripts/jquery-ui.min.js").exist?
            jq_defaults = %w(jquery jquery-ui)
            jq_defaults.map!{|a| a + ".min" } if ::Rails.env.production? || ::Rails.env.test?
          else
            jq_defaults = ::Rails.env.production? || ::Rails.env.test? ? %w(jquery.min) : %w(jquery)
          end

          # Merge the jQuery scripts, remove the Prototype defaults and finally add 'jquery_ujs'
          # at the end, because load order is important
          config.action_view.javascript_expansions[:defaults] -= PROTOTYPE_JS + ['rails']
          config.action_view.javascript_expansions[:defaults] |= jq_defaults + ['jquery_ujs']
        end
      end
    end
  end
end

Check for config options only inside the before_configuration hook
Check for config options only inside the before_configuration hook

This fixes calling "bundle console" from Rails, without this change we
get the following error:

     undefined method `action_view' for
     #<Rails::Railtie::Configuration:0x007fdb842b4cd0> (NoMethodError)`
