How to extend ActionController correctly in rails plugin

I am writing a Rails plugin (let's call it Foo). I want it to provide a "bar" class function in controllers so that I can:

class ApplicationController
  bar ...
end

barIt is determined from a call to the plugin loader file / plugins / foo / init.rb. Sort of

class ActionController::Base
  def self.bar
    ...
  end
end

The problem is that some other plugins (in my case the ResourceController) can load before foo and access the ApplicationController.

So what happens is that the ApplicationController is loaded before the "foo" plugin and does not work, since there is no "bar" defined by YET .

So ... how do I get it to work correctly ?

, , ActionController (, inherited_resources, resource_controller), , , , , , .

, ApplicationController 'foo'. , "foo".

"require". :)

0
2

. . :

# in RAILS_ROOT/config/environment.rb:
...
Rails::Initializer.run do |config|
  # load Bar before Foo, then everything else:
  config.plugins = [ :bar, :foo, :all ]
  ...
end
+1

, ,

ResourceController foo bar, foo. , . ( rails/railties/lib/initializer.rb). , .

, :

module ActionController
  class Base
     class << self
       ... # Class methods here
     end
  ... # Instance methods here
  end
end
0