我想添加两个不同的附件字段.迁移失败了我使用bundler或不使用bundler运行它. (bundle exec rake db:migrate或者只是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’,但这根本没有帮助.