Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Patch for #1458 - [3.1.0.rc1] App plugins initialized before engines and plugins inside engines #1735

Merged
merged 1 commit into from Jun 16, 2011

Conversation

Projects
None yet
2 participants
Contributor

jhtwong commented Jun 16, 2011

Patch for #1458 - [3.1.0.rc1] App plugins initialized before engines and plugins inside engines

It seems that plugins inside a Rails 3.1 application proper (i.e. in /vendor/plugins) are initialized before engines and plugins inside engines.

After some debugging, I found the culprit in Rails::Application::Railties#all:

  def all(&block)
    @all ||= railties + engines + super
    @all.each(&block) if block
    @all
  end

The call to super here implicitly passes the &block argument, which has the unfortunate side-effect of adding the plugin initializers first (in front of other railties and engines) in the case of Rails::Engine#initializers:

def initializers
  initializers = []
  railties.all { |r| initializers += r.initializers }
  initializers += super
  initializers
end

The solution here is to replace the super call with a call to #plugins.

Patch for #1458 - [3.1.0.rc1] App plugins initialized before engines
and plugins inside engines

It seems that plugins inside a Rails 3.1 application proper (i.e. in
/vendor/plugins) are initialized before engines and plugins inside
engines.

After some debugging, I found the culprit in
Rails::Application::Railties#all:

  def all(&block)
    @all ||= railties + engines + super
    @all.each(&block) if block
    @all
  end

The call to super here implicitly passes the &block argument, which
has the unfortunate side-effect of adding the plugin initializers
first (in front of other railties and engines) in the case of
Rails::Engine#initializers:

def initializers
  initializers = []
  railties.all { |r| initializers += r.initializers }
  initializers += super
  initializers
end

The solution here is to replace the super call with a call
to #plugins.

josevalim added a commit that referenced this pull request Jun 16, 2011

Merge pull request #1735 from SAP-Oxygen/3-1-stable-app_plugins_order…
…ing_patch

Patch for #1458 - [3.1.0.rc1] App plugins initialized before engines and plugins inside engines

@josevalim josevalim merged commit f24d8fa into rails:3-1-stable Jun 16, 2011

Contributor

josevalim commented Jun 16, 2011

Can you send the same pull request for master please?

Contributor

jhtwong commented Jun 16, 2011

Patch for master submitted as #1737

jake3030 pushed a commit to jake3030/rails that referenced this pull request Jun 28, 2011

Fixed broken after_save callback; was being called when before_create…
… was canceled or before_update was canceled

Signed-off-by: Michael Koziarski <michael@koziarski.com>
[#1735 state:committed]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment