Fumisky Wells
Fumisky Wells

Reputation: 1199

how to integrate rails_config under rails engine

I'm trying to use rails_config for my rails engine config. It looks like not loaded automatically on test/dummy app because it's path is not under Rails.root (Rails.root is test/dummy and config for this engine is under config (not test/dummy/config)).

How to use rails_config for my engine?

Thanks and Best Regards,

Upvotes: 2

Views: 512

Answers (2)

Roman Trofimov
Roman Trofimov

Reputation: 109

If you use rails_config both in you rails app and rails engine, you should use Settings.add_source!(...) instead of Settings.reload_from_files(...) as the last one rewrites global Settings object.

initializer "my_engine.settings" do
  Settings.add_source!(
    MyEngine::Engine.root.join('config', 'settings.yml').to_s
  )
  Settings.reload!
end

Upvotes: 1

Fumisky Wells
Fumisky Wells

Reputation: 1199

Here my answer by using Settings.reload_from_files method is:

module MyEngine
  class Engine < ::Rails::Engine
    def self.load_config
      engine_config_dir = Pathname.new(File.expand_path('../../../config', __FILE__))
      Settings.reload_from_files(
          (engine_config_dir + 'settings.yml').to_s,
          (engine_config_dir + "settings/#{Rails.env}.yml").to_s
      )
    end

    initializer "my_engine" do
      Engine::load_config
      ...
    end
  end
end

Upvotes: 3

Related Questions