开发者

Trouble Getting s3 set up in Rails 3 Refinery CMS App

I'm trying to get my refinery cms image storage to Amazon s3 and I'm following this guide:

http://refinerycms.com/guides/how-to-use-amazon-s3-for-storage

But I'm blocked here:

There are a number of ways to set these with your credentials, including unix variables or settings them manually through Ruby using ENV.

How do I define these credentials. Do I put something like :S3_KEY => "my_key" in my environments.rb file? I tried this and it didn't work. I also tried this:

AWS::S3::Base.establish_connection!(
 :access_key_id     => ENV['S3_KEY'] || 'key_goes_here',
 :secret_access_key => ENV['S3_SECRET'] || 's3_secret_key_here',
)

Can't figure out 开发者_如何学运维how to do this. Any ideas are greatly appreciated.


The safest way is to specify them as environment variables, so they aren't included in your source code. If you're the only one with access to the source, then specifying them as you describe should work.

You can specify them in your ~/.bashrc

export S3_KEY=mykey
export S3_SECRET=mysecret

Or if you're just testing locally you can prepend them to your rails command.

$ S3_KEY=mykey S3_SECRET=mysecret rails server

If you don't want to/can't use environment variables, another method is to use an initializer to load credentials from a yml file: config/initializers/s3_credentials.rb

# Load AWS::S3 configuration values
#
S3_CREDENTIALS = \
    YAML.load_file(File.join(Rails.root, 'config/s3_credentials.yml'))[Rails.env]

# Set the AWS::S3 configuration
#
AWS::S3::Base.establish_connection! S3_CREDENTIALS['connection']

config/s3_credentials.yml

development: &defaults
connection:
    :access_key_id: AAAAAA_your-key-here
    :secret_access_key: 4rpsi235js_your-secret-here
    :use_ssl: true
    bucket: project-development
    acl: public-read

production:
    <<: *defaults
    bucket: project
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜