模型缺少“photo_file_name”所需的 attr_accessor;在heroku上使用回形针和S3上传时
在我的 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
这确实使模型缺少“photo_file_name”所需的 attr_accessor我的其他问题。正如我发现的,将 attr_accessor 行添加到我的模型中,即使在我的开发系统上上传也会失败,我怀疑这不是正确的答案。
Setting up paperclip with S3 in my linux dev environment was a snap -- everything works out of the box. However, I can't get it to work on Heroku.
When I try to do an upload, the log shows:
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'):
I found one blog post that referenced this error, and it said to add this to my model:
attr_accessor :photo_file_name
attr_accessor :photo_content_type
attr_accessor :photo_file_size
attr_accessor :photo_updated_at
That does indeed make the model missing required attr_accessor for 'photo_file_name' error go away, but it still doesn't work. See my other question for details. As I have figured out that with the attr_accessor lines added to my model the uploads fail even on my dev system, I suspect that is not the right answer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
发现问题:需要更新数据库。
我已经做了我认为已经完成同样事情的事情:
但也许这不起作用或者在此过程中出现问题。
Found the problem: needed to update the database.
I had done what I thought would have accomplished the same thing already:
but perhaps that doesn't work or something went wrong in the process.
如果您在迁移中创建了错误的列类型,则会出现此类错误。当您为回形针定义新表迁移时,您需要指定
t.attachment :name
而不是t.string :name
。或者当您在现有表中添加新回形针列时add_attachment :table, :name
。现在您不需要在模型的attr_accessor
中添加这些属性。Error like this occurs if you create wrong column type in migration. When you define new table migration for paperclip, you need to specify
t.attachment :name
insted oft.string :name
. Oradd_attachment :table, :name
when you add new paperclip column in existed table. And now you don't need to add these attributes inattr_accessor
in model.嗯,这条消息似乎是因为它缺少列。尝试创建一个迁移,创建列:
结束
这对我有用,这里我有一个带有照片的表事件
Well, this message seems to be because the columns it's missing. Try create a migration creating the columns:
end
This work for me, here i have a table events with photo