在我的web应用程序中,我想访问初始化程序文件中的环境变量。我的intiailizer文件看起来像(initializers/gcm_on_Rails.rb)
configatron.gcm_on_rails.api_url = 'https://android.googleapis.com/gcm/send'
#configatron.gcm_on_rails.api_key = 'abc'
configatron.gcm_on_rails.api_key == ENV['GCM_API_KEY']
Rails.logger.debug"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ #{configatron.gcm_on_rails.api_key}"
configatron.gcm_on_rails.app_name = 'com.xyz'
configatron.gcm_on_rails.delivery_format = 'json'在我的.bashrc文件中,我添加了以下键值
export GCM_API_KEY="abc"但是我的记录器没有给我任何价值。这意味着我无法访问这些环境变量。我想访问这些变量。需要帮助..。谢谢你……
发布于 2012-09-21 14:23:05
如果在/etc/bashrc或/etc/profile中设置了环境变量,那么可以在shell中使用这些环境变量。但是,在大多数操作系统上,Apache不是从shell启动的,并且不加载在bashrc/profile中定义的环境变量,这就是为什么在/etc/bashrc和/etc/profile中设置环境变量通常不会对Apache (以及归纳、乘客和Rails进程)产生影响。
参考:- http://blog.phusion.nl/2008/12/16/passing-environment-variables-to-ruby-from-phusion-passenger/
https://stackoverflow.com/questions/12524971
复制相似问题