0

我正在使用回形针将图像附加到我的 rails 应用程序中的优惠。该代码在开发中有效,但在暂存中无效。在暂存中,图像正确保存到 s3,但它image_file_name是 nil。

db/migrate/20130507182116_add_image_to_offers.rb

class AddImageToOffers < ActiveRecord::Migration
  def self.up
    add_attachment :offers, :image
  end

  def self.down
    remove_attachment :offers, :image
  end
end

应用程序/模型/offer.rb

class Offer < ActiveRecord::Base
  attr_accessor :image

  has_attached_file :image, styles: {
    thumb: '100x100>',
    square: '200x200#',
    medium: '300x300>'
  }

当我在开发模式下运行以下配置时,它可以工作,当我切换到登台时,我收到以下错误:

Paperclip::Error (Offer model missing required attr_accessor for 'image_file_name'):

如果我添加attr_accessor :image_file_name到它完成的模型并将图像保存到 s3,但属性nil在数据库中。

4

1 回答 1

1

请务必迁移您的数据库。此外,如果您使用的是 heroku,则需要重新启动服务:在 heroku 上使用回形针和 S3 上传时,模型缺少“photo_file_name”所需的 attr_accessor

于 2013-05-21T21:49:58.990 回答