views:

28

answers:

1

When creating a rails engine in 2.3.5 as a plugin, how can the gem dependencies be set within the plugin, without having to import them into the host applications environment.rb?

Basically, I need to be able to call "config.gem" after Initializer.run has been called by environment.rb, since the plugin has not been loaded when the config block is in scope.

Not using bundler for this application.

A: 

I think that you can run the Rails Initializer stuff inside your init.rb eg just stuff like:

Rails::Initializer.run do |config|
  config.gem 'fastercsv', :version => '1.4.0'    
  config.gem 'liquid', :version => '2.0.0'
end

If putting it in init.rb doesn't call it, one of our engines has a bootfile that simply contains a class with a method that contains the same Initialiser stuff as above. eg:

class MyBootClass
  def self.boot_up  
    Rails::Initializer.run do |config|
      config.gem 'fastercsv', :version => '1.4.0'    
      config.gem 'liquid', :version => '2.0.0'
    end
  end
end

The bootfile is required in the environment.rb and the class method called eg

require "#{File.dirname(__FILE__)}/../vendor/plugins/.../bootfile.rb"
MyBootClass.boot_up
Taryn East
Thank you--this is effectively the solution I have reluctantly come to as well. Was hoping to keep things self-contained within the plugin, but perhaps that will have to wait for Rails 3.0...
fullware