当用曲别针和S3在Heroku上上传模型缺少必需的attr_accessor为“photo_file_name”曲别针、模型、上传、photo_file_name

2023-09-11 08:14:03 作者:醉风吹客衣

在我的Linux开发环境设置回形针与S3是易如反掌 - 一切正常开箱。但是,我无法得到它的工作在Heroku上。

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

这确实使模型缺少photo_file_name错误消失要求attr_accessor,但它仍然无法正常工作。请参阅my另一个问题,了解详细信息。正如我已经想通了,与attr_accessor线添加到我的模型上传我开发的系统故障,甚至,我怀疑是不是正确的答案。

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.

推荐答案

发现问题:需要对数据库进行更新

Found the problem: needed to update the database.

Heroku的运行rake:分贝:迁移

heroku run rake:db:migrate

Heroku的重启

我已经做了我认为将完成同样的事情早已:

I had done what I thought would have accomplished the same thing already:

Heroku的耙分贝:模式:负载

heroku rake db:schema:load

但也许不工作或出事了这一进程。

but perhaps that doesn't work or something went wrong in the process.