RoR:无法将回形针连接到Amazon S3

时间:2010-01-06 14:38:35

标签: ruby-on-rails ruby-on-rails-plugins amazon paperclip amazon-s3

我决定将我的应用程序部署到Heroku,我正在按照他们的教程进行操作。但是,我正在尝试使用回形针插件连接到我的Amazon S3存储桶,我收到此错误:

  

图像中的ArgumentError #index

     

显示第19行引出的app / views / images / index.html.erb:

     第0行,第39栏

语法错误:`bucket :(我的桶在这里)
  access_key_id :(我的访问密钥ID)   secret_access_key :(我的秘密访问密钥在这里)
  “
  提取的来源(第19行):

     

16:<%= h image.created_at%>
  17:<%= h image.updated_at%>
  18:
  19:<%if image.img.exists?那么%>
  20:

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


  21:<%else%>
  22:

没有附加照片,上传一张。

     

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

     

应用程序跟踪|框架跟踪|完整跟踪
  C:/Ruby/lib/ruby/1.8/yaml.rb:133:在load'
C:/Ruby/lib/ruby/1.8/yaml.rb:133:in
加载'中   C:/Users/Mariusz/Sites/wiw_development/vendor/plugins/paperclip/lib/paperclip/storage.rb:236:在find_credentials'
C:/Users/Mariusz/Sites/wiw_development/vendor/plugins/paperclip/lib/paperclip/storage.rb:176:in
parse_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:in
instance_eval'
  C:/Users/Mariusz/Sites/wiw_development/vendor/plugins/paperclip/lib/paperclip/storage.rb:137:in extended'
C:/Users/Mariusz/Sites/wiw_development/vendor/plugins/paperclip/lib/paperclip/attachment.rb:269:in
extend'
  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:in
初始化'
  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:in
attachment_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'

我的文件如下:

1)app / models / image.rb

  

class Image<的ActiveRecord :: Base的
   has_and_belongs_to_many:对    validates_presence_of:img_file_name
   has_attached_file:img,:styles => {:拇指=> “100x100#”,:page => “400x320>”},:storage => :s3,:s3_credentials => “#{RAILS_ROOT} /config/s3.yml”
  结束

2)config / s3.yml

  桶:(我的桶在这里)
  access_key_id :(我的访问密钥ID)   secret_access_key :(我的秘密访问密钥)

我怎样才能让它发挥作用?

2 个答案:

答案 0 :(得分:9)

C:/Ruby/lib/ruby/1.8/yaml.rb:133:in load' - 这是一个YAML错误。您可能有一个格式错误的YML文件。 在脚本/控制台中尝试此代码:

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

以下是我的工作配置示例:

  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"

和yml文件:

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

答案 1 :(得分:0)

你是对的。我的'e'文本编辑器将yaml文件保存为一种奇怪的格式,带有一些额外的字符。现在一切正常。谢谢!