我正在尝试在我的Rails 3.2应用程序中使用Paperclip gem和Amazon S3。但是,当我添加时出现问题:storage => :s3和S3信息以及生成表单。
错误:
undefined method `photo' for #<PlacePhoto:0x007fdbbd1e75a8>
提取的来源(第78行):
75: <% end %>
76:
77: <%= f.simple_fields_for :place_photos do |photo| %>
78: <%= photo.input :photo %>
79: <%= photo.input :description,
80: :label => "Photo label",
81: :input_html => { :class => 'span4', :rows => 2 } %>
型号:
class PlacePhoto < ActiveRecord::Base
has_attached_file :photo,
:styles => { :medium => "300x300#", :thumb => "100x100#" },
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:path => "/:style/:id/:filename"
attr_accessible :description, :photo
belongs_to :place
validates_attachment :photo,
:presence => true,
:content_type => { :content_type => /image/ },
:size => { :in => 0..2.megabytes }
end
移植
class CreatePlacePhotos < ActiveRecord::Migration
def change
create_table :place_photos do |t|
t.text :description
t.integer :place_id
t.has_attached_file :photo
t.timestamps
end
end
end
我使用下面的文章来实现S3:http://doganberktas.com/2010/09/14/amazon-s3-and-paperclip-rails-3/。我做了捆绑安装,rake db:migrate并重启服务器。
有趣的是,当模型缺少S3信息时,错误不会出现并且正在生成表单:
型号(其他版本):
class PlacePhoto < ActiveRecord::Base
has_attached_file :photo,
:styles => { :medium => "300x300#", :thumb => "100x100#" }
attr_accessible :description, :photo
belongs_to :place
validates_attachment :photo,
:presence => true,
:content_type => { :content_type => /image/ },
:size => { :in => 0..2.megabytes }
end
答案 0 :(得分:1)
通过改变解决问题:
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
要
:s3_credentials => "#{Rails.root}/config/s3.yml",