【问题标题】:image saved but missing using paperclip使用回形针保存但丢失的图像
【发布时间】:2013-05-30 03:41:16
【问题描述】:

我在我的 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

app/models/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

【问题讨论】:

    标签: ruby-on-rails paperclip


    【解决方案1】:

    请务必迁移您的数据库。此外,如果您使用 heroku,则需要重新启动服务:model missing required attr_accessor for 'photo_file_name' when uploading with paperclip and S3 on heroku

    【讨论】:

      猜你喜欢
      • 2013-06-25
      • 1970-01-01
      • 2018-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多