How do I change the load order of initializers in Rails 3?

前端 未结 4 1781
名媛妹妹
名媛妹妹 2020-12-24 10:43

I have an initializer that loads configuration settings from a yaml file. I need to use these settings in other initializers. The settings are not being seen by the initiali

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-24 11:12

    Put the configuration code in config/environment.rb file, right after the first require statement, such as:

    # Load the rails application
    require File.expand_path('../application', __FILE__)
    
    # Load global configurations
    CONFIG = Hashie::Mash.new YAML.load_file(Rails.root.join("config", "application.yml"))[Rails.env]
    
    # Initialize the rails application
    RailsSetup::Application.initialize!
    

提交回复
热议问题