Rails3 - how to get aws-s3 yml configuration data in an application?

In particular, I have a config / amazon_s3.yml file that aws-s3 gem uses to configure some s3 configuration settings, such as private keys, etc. I also write some of this data in var ENV in another file in the initializers, so I can refer to them in calls to the has_attached_file method used by paperclip.

It would be wiser to get the file in the initializers to read them from s3 config yml or some configuration settings for the classes used by the stone, for example, something like AWS::S3::Base.connection.secret_access_key (this does not work).

Any ideas?

+2
ruby-on-rails yaml ruby-on-rails-3 amazon-s3
source share
1 answer

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

First I load into yaml and paste it into a constant.

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

Then, when I create a paperclip for the model, pull these values, making sure that 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 
+9
source share

All Articles