Reputation: 1050
I was in a course last year to develop RoR applications. I developed one that searches AWS using my account's key and returns results. Now whenever I search Amazon I'm getting a 403 error.
I recreated my key and I've updated it in the Rails console but to no avail. How can I check my credentials or what else can I do to start hunting this problem down?
Upvotes: 0
Views: 395
Reputation: 1279
I would set the location of the keys in a new .yml file called aws.yml under config/locales/ as following:
development:
access_key_id: XXXXXXXXXXXXXX
secret_access_key: XXXXXXXXXXXXXXXX
s3_region: eu-central-1
test:
access_key_id: XXXXXXXXXXXXXXXX
secret_access_key: XXXXXXXXXXXXXXXX
s3_region: eu-central-1
production:
access_key_id: XXXXXXXXXXXXXXXX
secret_access_key: XXXXXXXXXXXXXXXX
s3_region: eu-central-1
And then in the model which has the attached file as in:
has_attached_file :img
You can set the s3_credentials as
s3_credentials: "#{Rails.root}/config/aws.yml",
So the final result in your model should look like this:
has_attached_file :img,
styles: { :model_index => "250x350", :img_show => "325x475"},
storage: :s3,
url: ':s3_domain_url',
bucket: 'yourbucket',
s3_credentials: "#{Rails.root}/config/aws.yml",
path: "resources/:id/:style/:basename.:extension"
And then in your view:
<%= @model.model_img.url(:img_show) %>
And there you have it!
Upvotes: 1