模型缺少“photo_file_name”所需的 attr_accessor;在heroku上使用回形针和S3上传时

发布于 2024-09-16 08:22:37 字数 1077 浏览 6 评论 0原文

在我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

許願樹丅啲祈禱 2024-09-23 08:22:37

发现问题:需要更新数据库。

heroku 运行 rake:db:migrate

heroku 重启

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

heroku rake db:schema:load

但也许这不起作用或者在此过程中出现问题。

Found the problem: needed to update the database.

heroku run rake:db:migrate

heroku restart

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

heroku rake db:schema:load

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

总攻大人 2024-09-23 08:22:37

如果您在迁移中创建了错误的列类型,则会出现此类错误。当您为回形针定义新表迁移时,您需要指定 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 of t.string :name. Or add_attachment :table, :name when you add new paperclip column in existed table. And now you don't need to add these attributes in attr_accessor in model.

遥远的她 2024-09-23 08:22:37

嗯,这条消息似乎是因为它缺少列。尝试创建一个迁移,创建列:

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

结束

这对我有用,这里我有一个带有照片的表事件

Well, this message seems to be because the columns it's missing. Try create a migration creating the columns:

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

end

This work for me, here i have a table events with photo

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文