0

我决定将我的应用程序部署到Heroku,并且我正在关注他们的教程。然而,我试着用一个回形针插件连接到我的Amazon S3的桶,现在和进出口收到此错误:RoR:无法将回形针连接到Amazon S3

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:in
load'
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: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
initialize'
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)应用程序/模型/ 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)配置/ s3.yml

bucket: (MY BUCKET HERE)
access_key_id: (MY ACCESS KEY ID HERE)
secret_access_key: (MY SECRET ACCESS KEY HERE)

我怎样才能得到它的工作?

回答

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: *** 
0

你是对的。我的'e'文本编辑器以一种奇怪的格式保存了yaml文件,并添加了一些额外的字符。一切正在工作。谢谢!

+0

:)不客气。 – 2010-01-11 20:42:36

+0

还有一件事:如果我的回答对您有帮助,请将其标记为您的问题的答案(绿色复选标记):) 10qu – 2010-01-12 10:42:43