简体   繁体   English

为开发环境设置rails fog gem application.yml密钥

[英]set rails fog gem application.yml keys for development environment

I'm using paperclip, fog, figaro gems to upload images to amazon S3. 我正在使用回形针,雾气,无花果宝石将图像上传到亚马逊S3。 In production works fine as I introduced the env variables in heroku by hand. 在生产中运行良好,因为我手动在heroku中引入了env变量。

But in development, it is suposed to use the env from the aplication.yml file (added to .gitignore). 但是在开发中,建议使用aplication.yml文件(添加到.gitignore)中的env。 It is not using this file, as in development the ENV[] placed in application.yml do not exist. 它未使用此文件,因为在开发中,放置在application.yml中的ENV []不存在。

I followed several tutorial for this, and in all of them I understand that the ENV[] introduced in applicaction.yml should be used. 我遵循了几个教程,在所有这些教程中,我都了解应该使用applicaction.yml中引入的ENV []。 Am I wrong? 我错了吗? Am I missing something? 我想念什么吗? Do I need something else? 我还需要其他东西吗? I read that I can introduce the ENV[] by hand typing export, but I need to know if it is not enough to write them down at application.yml 我读到可以手工输入export来介绍ENV [],但是我需要知道是否不足以在application.yml上写下它们。

#config/application.yml    
MAPS_API_KEY: 1234googlemapapikey56788

SECRET_KEY_BASE: ab1234567longkeyy2979127401411124
AWS_ACCES_KEY_ID: ACCESSKEYID1234567
AWS_SECRET_ACCESS_KEY: SECRETKEY123456788/jaa\12345
AWS_REGION: eu-west-1
S3_HOST_NAME: s3-eu-west-1.amazonaws.com

development:
  FOG_DIRECTORY: example-dev
  S3_BUCKET_NAME: example-dev
production:
  FOG_DIRECTORY: example-production
  S3_BUCKET_NAME: example-production

in development and production I use the same code: 在开发和生产中,我使用相同的代码:

#config/environments/development.rb && config/environments/production.rb
config.paperclip_defaults = {
storage: :s3,
s3_credentials: {
    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'),
  }
}

In production works fine, and in development I get errors like: development.rb:54:in `fetch': key not found: "AWS_ACCESS_KEY_ID" (KeyError) 在生产中工作正常,在开发中我得到如下错误:development.rb:54:in'fetch':key not found:“ AWS_ACCESS_KEY_ID”(KeyError)

# config/initializers/paperclip.rb
Paperclip::Attachment.default_options[:url] = ':s3_domain_url'
Paperclip::Attachment.default_options[:path] = '/:class/:attachment/:id_partition/:style/:filename'

The config/application.yml you list above has a typo. 您上面列出的config/application.yml有一个错字。

The key you want is AWS_ACCESS_KEY_ID , but the copied file uses AWS_ACCES_KEY_ID (where access is missing the second s ). 您想要的密钥是AWS_ACCESS_KEY_ID ,但是复制的文件使用AWS_ACCES_KEY_IDaccess缺少第二个s )。

I suspect that should get things working for you again. 我怀疑那会让事情再次为您工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM