Is it possible to set ENV variables for rails development environment in my code?

后端 未结 7 1230
心在旅途
心在旅途 2020-11-27 09:59

I know that I can set my ENV variables in bash via

export admin_password = \"secret\"

But is there a way to do it in my rails source code s

7条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-27 10:28

    I think the best way is to store them in some yml file and then load that file using this command in intializer file

    APP_CONFIG = YAML.load_file("#{Rails.root}/config/CONFIG.yml")[Rails.env].to_hash
    

    you can easily access environment related config variables.

    Your Yml file key value structure:

    development:
      app_key: 'abc'
      app_secret: 'abc'
    
    production:
      app_key: 'xyz'
      app_secret: 'ghq'
    

提交回复
热议问题