Rails 3 / Setting Custom Environment Variables

后端 未结 4 1339
北荒
北荒 2020-12-13 10:54

I am trying to create a rails application that assigns one value to a variable when the environment is the development environment, and another value to that same variable w

4条回答
  •  不知归路
    2020-12-13 11:23

    I use the Yettings gem in Rails 3.2, which allows me to store my application variables in config/yettings.yml like so:

    defaults: &defaults
      api_key: asdf12345lkj
      some_number: 999
      an_erb_yetting: <%= "erb stuff works" %>
      some_array:
        - element1
        - element2
    
    development:
      <<: *defaults
      api_key: api key for dev
    
    test:
      <<: *defaults
    
    production:
      <<: *defaults
    

    And access them like this:

    #/your_rails_app/config/yetting.yml in production
    Yetting.some_number #=> 999
    Yetting.api_key #=> "asdf12345lkj"
    

提交回复
热议问题