【问题标题】:rails 4 Paperclip: undefined method `brand_logo_image_content_type' for #<Batch:0x431a408>rails 4 Paperclip:#<Batch:0x431a408> 的未定义方法“brand_logo_image_content_type”
【发布时间】:2015-01-24 06:52:38
【问题描述】:

我正在尝试将 rails app 项目从版本 3 迁移到 rails 版本 4.0.0 。我正在尝试使用版本(4.2.1)的回形针 gem 保存图像,但出现以下错误

undefined method `brand_logo_image_content_type' for #<Batch:0x431a408>

下面是我的模型

class Batch < ActiveRecord::Base
  has_attached_file :brand_logo_image, :styles => {:thumb => "16x16>" }
  validates_attachment_content_type :brand_logo_image, :content_type => /\Aimage\/.*\Z/
  validates_attachment_presence :brand_logo_image
  validates_attachment_size :brand_logo_image, :less_than => 1.megabytes, :unless => Proc.new {|m| m[:brand_logo_image].nil?}
end

谢谢,

【问题讨论】:

  • 您是否创建了相关的迁移? rails paperclip Batch brand_logo_image &amp;&amp; rake db:migrate

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-4 devise


【解决方案1】:

游戏晚了,但为了后代:您可能没有在迁移中添加必要的列。

确保你有变化

add_attachment :batch, :brand_logo_image

或向上

change_table :batch do |t|
  t.attachment :brand_logo_image
end

应该在表中创建适当的列:

batch_file_name
batch_file_size
batch_content_type
batch_updated_at

【讨论】:

    猜你喜欢
    • 2012-04-09
    • 1970-01-01
    • 1970-01-01
    • 2019-06-17
    • 2015-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多