Vitaly Kushner
Vitaly Kushner

Reputation: 9455

how to control gems vs plugins loading order in Rails

I have a plugin that must be loaded before resource_controller. The reason is that Resourcecontroller tries to load ApplicationController and it depends on the said plugin (and will fail to load if plugin's init.rb was not loaded yet).

The problem is that ResourceController comes from a gem and not a plugin.

Is there a way to load plugins before the gems (from environment.rb's "config.gem ...")?

Upvotes: 3

Views: 2022

Answers (3)

james2m
james2m

Reputation: 1580

For rails2.3x in environment.rb set your gem to lib => false and then require the gem in the after_initialize block

config.gem 'some_gem', :lib => false
config.after_initialize do
  require 'some_gem'
end

That'll do it.

Upvotes: 1

James Adam
James Adam

Reputation: 1079

There's no present way to load plugins before gems if you depend exclusively on config.gem to load them, but that doesn't mean that you can't take the loading of the resource_controller gem into your own hands.

As a very brutal solution, you can remove the relevant config.gem line, and then explicitly 'require' it at the bottom of environment.rb.

Upvotes: 2

amitkaz
amitkaz

Reputation: 2712

a quick glance at the Initializer.rb code shows:

  load_gems
  load_plugins

  # pick up any gems that plugins depend on
  add_gem_load_paths
  load_gems
  check_gem_dependencies

If I understand it correctly, gems always comes before plugins... then some gems that the plugins require.

why not use resource_controller as a plugin, also? just don't use the "config.gem ..." and put it in the plugins directory.

Upvotes: 0

Related Questions