我正在尝试在我的 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