Ruby on Rails环境变量用于开发环境 [英] Ruby on Rails environment variable for development environment

查看:205
本文介绍了Ruby on Rails环境变量用于开发环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是一个很简单的问题,我无法在stackoverflow上找到答案。



如果对于分段和生产环境变量很容易(例如在heroku上),我如何为我的localhost(开发环境)设置环境变量? (我在mac上)



截至今天,我为我的api凭据硬编码开发环境,我感到不舒服。



谢谢!

解决方案

使用 dotenv 旨在用于开发中:



将您的应用程序配置添加到项目根目录中的 .env 文件。

  S3_BUCKET =你的宝贝
SECRET_KEY =你的钱也可以在每行之前添加导出,以便您可以在bash中输入文件。
$ .bashrc

  export S3_BUCKET = YOURS3BUCKET 
export SECRET_KEY = YOURSECRETKEYGOESHERE

然后在rails应用程序中访问 ENV ['S3_BUCKET ']


Just a quick question to which I couldn't find an answer on stackoverflow.

If it is easy to have environment variable for staging and production (on heroku for example), how can I set environment variable for my localhost (development environment)? (I am on a mac)

As of today I hardcode my api credential for development environment and I don't feel comfortable with that.

Thanks !

解决方案

Use dotenv is intended to be used in development:

Add your application configuration to your .env file in the root of your project.

S3_BUCKET=YOURS3BUCKET
SECRET_KEY=YOURSECRETKEYGOESHERE

You may also add export in front of each line so you can source the file in bash. in .bashrc

export S3_BUCKET=YOURS3BUCKET
export SECRET_KEY=YOURSECRETKEYGOESHERE

Then access in rails app ENV['S3_BUCKET']

这篇关于Ruby on Rails环境变量用于开发环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆