Rails3 - 如何让在应用程序AWS-S3的阳明配置数据? [英] Rails3 - how to get at aws-s3's yml config data in the app?

查看:97
本文介绍了Rails3 - 如何让在应用程序AWS-S3的阳明配置数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

具体而言,我有一个文件config / amazon_s3.yml所使用的AWS-S3创业板设立类似的密钥等一些S3的配置设置,我也写一些这方面的数据为在ENV一个变种在不同的在初始化文件,所以我可以引用他们呼吁用回形针的has_attached_file的方法。

Specifically, i have a file config/amazon_s3.yml which is used by the aws-s3 gem to set up some s3 config settings like secret keys etc. I also write some of this data into a var in ENV in a different file in initializers so i can reference them in calls to the "has_attached_file" method used by paperclip.

这将是更聪明取得初始化文件中读取出来的S3配置阳明,或者所用的宝石,如类的一些配置设置类似 AWS :: S3 :: Base.connection.secret_access_key (这不工作)。

It would be smarter to get the file in initializers to read them out of the s3 config yml, or some config settings for the classes used by the gem, eg something like AWS::S3::Base.connection.secret_access_key (this doesn't work).

任何想法?

推荐答案

我在这里找到了答案的如何在配置使用阳明值/ initalizer

I found the answer here How to use YML values in a config/initalizer

首先,我加载在YAML,并坚持在一个常数。

First i load in the yaml in and stick it in a constant.

#config/initializers/constants.rb
S3_CONFIG = YAML.load_file("#{::Rails.root}/config/amazon_s3.yml")

然后,当我设置了曲别针为模型,在拉这些价值观,并确保我指的是当前环境:

Then, when i set up paperclip for a model, pull in these values, making sure i refer to the current environment:

class Entry < ActiveRecord::Base
  has_attached_file :media,
    :styles => { 
      :medium => "300x300>", 
      :thumb => "110x110>" 
    },
    :storage => :s3,
    :bucket =>S3_CONFIG[::Rails.env]["bucket"],
    :s3_credentials => {
      :access_key_id => S3_CONFIG[::Rails.env]["access_key_id"],
      :secret_access_key => S3_CONFIG[::Rails.env]["secret_access_key"]
    }        
end

这篇关于Rails3 - 如何让在应用程序AWS-S3的阳明配置数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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