title: How to append a before_filter in gem after all other controller before_filters in a Rails3 app?
body: <p>There's a gem, which <strong>appends</strong> a <code>before_filter</code> to a Rails app:</p>
  
  <pre><code>class Railtie &lt; Rails::Railtie
    initializer "..." do
      ActiveSupport.on_load(:action_controller) do
        ActionController::Base.send(:include, Filter)
  
  ...
  
  module Filter
    extend ActiveSupport::Concern
  
    included do
      append_before_filter :set_locale
    end
  
    def set_locale
       ....
  </code></pre>
  
  <p>And here's some controller in the app:</p>
  
  <pre><code>class DesktopsController &lt; ApplicationController
    before_filter :set_language_in_session
  </code></pre>
  
  <p>Now the problem with this is that the <code>before_filter</code> from the gem is being put in the filter chain before the <code>before_filter</code> from the DesktopsController:</p>
  
  <pre><code>DesktopsController._process_action_callbacks.select { |c| c.kind == :before }.collect { |filter| filter.filter }
  =&gt; [
      [0] :set_locale,
      [1] :set_language_in_session
  ]
  </code></pre>
  
  <p>How can I make the <code>before_filter</code> from the gem (<strong>set_locale</strong>) be put <strong>after</strong> all other filters? The secret probably lies in this line:</p>
  
  <pre><code>ActiveSupport.on_load(:action_controller) do
  </code></pre>
  
  <p>But I've tried different libraries without any luck...</p>
  
  <p>Btw. Here's the <a href="https://github.com/Exvo/locale_detector">full code</a> of the gem. Ruby 1.9.2, Rails 3.0.5.</p>