【问题标题】:rails with carrierwave migration error: undefined method `attachment'带有载波迁移错误的轨道:未定义的方法“附件”
【发布时间】:2013-04-24 13:04:02
【问题描述】:

我正在使用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


我该如何解决?

【问题讨论】:

  • 它对我没有帮助,仍然有'未定义的方法'附件''

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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-27
    • 1970-01-01
    • 1970-01-01
    • 2013-12-12
    • 2017-04-19
    • 1970-01-01
    • 2016-03-14
    相关资源
    最近更新 更多