具有carrierwave迁移错误的rails:未定义的方法`attachment'

时间:2013-04-24 13:04:03

标签: ruby-on-rails ruby-on-rails-3 carrierwave rails-migrations

我正在使用carrierwave gem(版本0.8.0)。当我做'rake db:migrate'时,我看到了一个奇怪的错误:



    ==  AddAttachmentLogoToMerchants: migrating ===================================
    -- change_table(:merchants)
    rake aborted!
    An error has occurred, this and all later migrations canceled:

    undefined method `attachment' for     ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::Table:0x007f900e6bde88

我的迁移:




      def self.up
        change_table :merchants  do |t|
          t.attachment :logo
        end
        remove_column :merchants, :logo_filename
      end

      def self.down
        add_column :merchants, :logo_filename, :string
        drop_attached_file :merchants, :logo
      end


我该如何解决?

1 个答案:

答案 0 :(得分:0)

t.attachment attachment中的AFAIK应为数据类型

change_table :merchants  do |t|
  t.attachment :logo
end

click here查找postgresql的数据类型列表 如果你想要字符串跟随应该工作

change_table :merchants  do |t|
  t.string :logo
end