开发者

RoR: not able to connect paperclip to Amazon S3

开发者 https://www.devze.com 2022-12-15 11:20 出处:网络
I have decided to deploy my app to Heroku and I was following their tutorials. However, Im trying to connect to my Amazon S3 bucket with a paperclip plugin right now and Im getting this error:

I have decided to deploy my app to Heroku and I was following their tutorials. However, Im trying to connect to my Amazon S3 bucket with a paperclip plugin right now and Im getting this error:

ArgumentError in Images#index

Showing app/views/images/index.html.erb where line #19 raised:

syntax error on line 0, col 39: `bucket: (MY BUCKET HERE)

access_key_id: (MY ACCESS KEY ID HERE)

secret_access_key: (MY SECRET ACCESS KEY HERE)

'

Extracted source (around line #19):

16: <%=h image.created_at %>

17: <%=h image.updated_at %>

18:

19: <% if image.img.exists? then %>

20:

<%= image_tag image.img.url(:thumb) %>

21: <% else %>

22:

There are no photo's attached, upload one.

RAILS_ROOT: C:/Users/Mariusz/Sites/wiw_development

Application Trace | Framework Trace | Full Trace

C:/Ruby/lib/ruby/1.8/yaml.rb:133:in load'

C:/Ruby/lib/ruby/1.8/yaml.rb:133:inload'

C:/Users/Mariusz/Sites/wiw_development/vendor/plugins/paperclip/lib/paperclip/storage.rb:236:in find_credentials'

C:/Users/Mariusz/Sites/wiw_development/vendor/plugins/paperclip/lib/paperclip/storage.rb:176:inparse_credentials'

C:/Users/Mariusz/Sites/wiw_development/vendor/plugins/paperclip/lib/paperclip/storage.rb:138:in extended'

C:/Users/Mariusz/Sites/wiw_development/vendor/plugins/paperclip/lib/paperclip/storage.rb:137:ininstance_eval'

C:/Users/Mariusz/Sites/wiw_development/vendor/plugins/paperclip/lib/paperclip/storage.rb:137:in extended'

C:/Users/Mariusz/Sites/wiw_development/vendor/plugi开发者_JS百科ns/paperclip/lib/paperclip/attachment.rb:269:inextend'

C:/Users/Mariusz/Sites/wiw_development/vendor/plugins/paperclip/lib/paperclip/attachment.rb:269:in initialize_storage'

C:/Users/Mariusz/Sites/wiw_development/vendor/plugins/paperclip/lib/paperclip/attachment.rb:51:ininitialize'

C:/Users/Mariusz/Sites/wiw_development/vendor/plugins/paperclip/lib/paperclip.rb:326:in new'

C:/Users/Mariusz/Sites/wiw_development/vendor/plugins/paperclip/lib/paperclip.rb:326:inattachment_for'

C:/Users/Mariusz/Sites/wiw_development/vendor/plugins/paperclip/lib/paperclip.rb:229:in img'

C:/Users/Mariusz/Sites/wiw_development/app/views/images/index.html.erb:19:in_run_erb_app47views47images47index46html46erb'

C:/Users/Mariusz/Sites/wiw_development/app/views/images/index.html.erb:12:in each'

C:/Users/Mariusz/Sites/wiw_development/app/views/images/index.html.erb:12:in_run_erb_app47views47images47index46html46erb'

C:/Users/Mariusz/Sites/wiw_development/app/controllers/images_controller.rb:7:in `index'

My files look like this:

1) app/models/image.rb

class Image < ActiveRecord::Base

has_and_belongs_to_many :pairs

validates_presence_of :img_file_name

has_attached_file :img, :styles => {:thumb=> "100x100#", :page => "400x320>"}, :storage => :s3, :s3_credentials => "#{RAILS_ROOT}/config/s3.yml"

end

2) config/s3.yml

bucket: (MY BUCKET HERE)

access_key_id: (MY ACCESS KEY ID HERE)

secret_access_key: (MY SECRET ACCESS KEY HERE)

How can I get it working?


C:/Ruby/lib/ruby/1.8/yaml.rb:133:in load' - this is a YAML error. You probably have a badly formatted YML file. Try this code in your script/console:

require 'yaml'
my_hash = YAML::load File.read("#{RAILS_ROOT}/config/s3.yml")

Below is an example from my working config:

  has_attached_file :data,
  :styles => {
    :small => "100x100#",
    :medium => "400x400#",
    :large => "640x480#"
  },
  :storage => :s3,
  :s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
  :path => ":attachment/:id/:style.:extension",
  :bucket => "xxx"

And the yml file:

development:
  access_key_id: ***
  secret_access_key: ***


You were right. My 'e' text editor was saving the yaml file in a strange format with some additional characters. Everything is working right now. THANKS!

0

精彩评论

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