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