views:

610

answers:

3

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 ...")?

A: 

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.

amikazmi
+1  A: 

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.

James Adam
A: 

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.

james2m