问题
I know there's a ton of these asked, but I've tried to follow each one with no luck. There must be some easy mistake that I am overlooking.
I'm trying to set up S3 and Paperclip following the Heroku guide and set up local testing following this Words and Code guide. Every time I try to generate a db migration though I get the error:
config/environments/development.rb:62:in fetch': key not found: "S3_BUCKET_NAME" (KeyError)
These are my files exactly with keys replaced:
development.rb
config.paperlip_defaults = {
storage: :s3,
s3_credientials: {
bucket: ENV.fetch('S3_BUCKET_NAME'),
access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID'),
secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY'),
s3_region: ENV.fetch('AWS_REGION')
}
}
.ENV
S3_BUCKET_NAME=some-bucket-name
AWS_ACCESS_KEY_ID=AAAAAABBBBBCCCCCDDDD
AWS_SECRET_ACCESS_KEY=AAAAABBBBBCCCCCDDDDDEEEEE
AWS_REGION=us-east-1
What am I missing?
Edit: I have tried adding the ENV values to my ~/.bashrc
and ~/.bash_profle
as suggested in this question, with the same error.
回答1:
The answer turned out to be pretty easy with a gem.
I added dotenv-rails
to my gemfile
group :development, :test do
gem 'dotenv-rails'
end
bundle install
and good to go.
I guess I never realized that the .env file saved in the root directory wasn't loaded automatically.
来源:https://stackoverflow.com/questions/42979019/key-is-there-but-i-still-get-fetch-key-not-found-s3-bucket-name-keyerror