为什么当我尝试为回形针添加附件字段时 db:migrate 失败? [英] Why is db:migrate failing when i try to add attachment fields for paperclip?

查看:36
本文介绍了为什么当我尝试为回形针添加附件字段时 db:migrate 失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试添加两个不同的附件字段.无论我是否使用捆绑器运行它,迁移都失败了.(捆绑 exec rake db:migrate 或只是 rake db:migrate).

I am trying to add two different attachment fields. The migration is failing wether i run it using bundler or without. (bundle exec rake db:migrate or just rake db:migrate).

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

undefined method `has_attached_file' for #<ActiveRecord::ConnectionAdapters::Table:0x0000012b003b20>
 /Users/kboon/Documents/workspace/quiztaker/db/migrate/20111213182927_add_diagram_to_question.rb:6:in `block in up'
 /Users/kboon/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:244:in `change_table'

迁移看起来像这样:

class AddDiagramToAnswer < ActiveRecord::Migration
  def self.up
    change_table :answers do |t|
      t.has_attached_file :diagram
    end
  end

  def self.down
    drop_attached_file :answers, :diagram
  end
end

该模型还引用了回形针添加的方法,并且该应用程序运行良好,因此根本没有安装回形针.我什至尝试在迁移中添加 require 'paperclip' ,但这根​​本没有帮助.

The model also references methods added by paperclip and the app runs fine so its not that paperclip isn't installed at all. I've even tried added require 'paperclip' to the migration but that didn't help at all.

推荐答案

为我创建的迁移不再使用 t.has_attached_file 术语,它实际上显式添加了列.将通过运行来创建迁移:

The migration that was created for me doesn't use the t.has_attached_file terminology anymore, it actually adds the columns explicitly. The migration would be created by running:

rails generate paperclip Answer diagram

此处查看示例.

这篇关于为什么当我尝试为回形针添加附件字段时 db:migrate 失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆