无法识别 rails 中 S3.yml 中的 ENV 变量 [英] Not recognizning ENV variables in S3.yml in rails
问题描述
我目前正在尝试使用最新的 aws-sdk
建议 gem 配置 Paperclip.
I'm currently trying to configure Paperclip with newest aws-sdk
suggested gem.
在我的 S3.yml 文件中,我有这样的东西
On my S3.yml file I have something like this
development:
bucket: newmeeter-dev
access_key_id: ENV['S3_KEY']
secret_access_key: ENV['S3_SECRET']
但它无法识别 ENV 变量.我收到以下错误
But it is not recognizing the ENV variables. I'm getting the following error
AWS::S3::Errors::InvalidAccessKeyId in PhotosController#create
The AWS Access Key Id you provided does not exist in our records.
如果我尝试将访问和秘密都直接放入文件中,它就可以完美运行.同时,我尝试将两个 ENV 变量打印到视图或控制台中,我可以看到它们的值.
If I try to put both the access and secret directly into the file it works perfectly. At the same time I tried to print both ENV variables into the views or in the console I can see their values okay.
我不明白为什么它不能识别它.
I'm not getting why it is not recognizing it.
推荐答案
已解决!
我在这里找到了这个问题的回复Ruby on Rails:你能将 Ruby 代码放在 YAML 配置文件中?
I found the reply to this question here Ruby on Rails: Can you put Ruby code in a YAML config file?
解决方案:YAML 文件理解 ERB 格式的代码.
Solution: YAML files understand code in ERB format.
在 <%=
和 %>
中打印 ENV 变量是有效的.
Printing ENV variables inside <%=
and %>
works.
access_key_id: <%= ENV['S3_KEY'] %>
secret_access_key: <%= ENV['S3_SECRET'] %>
这篇关于无法识别 rails 中 S3.yml 中的 ENV 变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!