在我的linux开发环境中使用S3设置回形针非常简单 - 一切都开箱即用。但是,我无法让它在Heroku上工作。
当我尝试上传时,日志会显示:
Processing ItemsController#create (for 72.177.97.9 at 2010-08-26 16:35:14) [POST]
Parameters: {"commit"=>"Create", "authenticity_token"=>"0Hy3qvQBHE1gvFVaq32HMy2ZIopelV0BHbrSeHkO1Qw=", "item"=>{"photo"=>#<File:/home/slugs/270862_4aa601b_4b6f/mnt/tmp/RackMultipart20100826-6286-1256pvc-0>, "price"=>"342", "name"=>"a new item", "description"=>"a new item", "sold"=>"0"}}
Paperclip::PaperclipError (Item model missing required attr_accessor for 'photo_file_name'):
我找到一篇引用此错误的博文,并说它将此添加到我的模型中:
attr_accessor :photo_file_name
attr_accessor :photo_content_type
attr_accessor :photo_file_size
attr_accessor :photo_updated_at
这确实使得模型缺失所需的attr_accessor'photo_file_name'错误消失了,但它仍然不起作用。有关详细信息,请参阅my other question。正如我已经发现,随着attr_accessor行添加到我的模型中,即使在我的开发系统上,上传也会失败,我怀疑这不是正确的答案。
答案 0 :(得分:30)
发现问题:需要更新数据库。
heroku run rake:db:migrate
heroku restart
我已经完成了我认为已经完成同样的事情:
heroku rake db:schema:load
但也许这不起作用或在此过程中出现问题。
答案 1 :(得分:4)
如果在迁移中创建错误的列类型,则会出现此错误。为回形针定义新表迁移时,您需要指定t.attachment :name
t.string :name
。或者在现有表格中添加新的回形针列时add_attachment :table, :name
。现在,您无需在模型中的attr_accessor
中添加这些属性。
答案 2 :(得分:0)
好吧,这条消息似乎是因为它缺少的列。尝试创建创建列的迁移:
class AddPhotoToEvent < ActiveRecord::Migration
def change
add_column :events, :photo_file_name, :string
add_column :events, :photo_content_type, :string
add_column :events, :photo_file_size, :integer
add_column :events, :photo_updated_at, :datetime
end
端
这项工作对我来说,这里有一个带照片的桌面活动