ruby-on-rails – 当我尝试为回形针添加附件字段时,为什么db:mi
发布时间:2020-12-16 19:21:23 所属栏目:百科 来源:网络整理
导读:我想添加两个不同的附件字段.迁移失败了我使用bundler或不使用bundler运行它. (bundle exec rake db:migrate或者只是rake db:migrate). == AddDiagramToQuestion: migrating ===========================================-- change_table(:questions)rake
我想添加两个不同的附件字段.迁移失败了我使用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’,但这根本没有帮助. 解决方法
为我创建的迁移不再使用t.has_attached_file术语,它实际上是显式添加列.将通过运行以下命令创建迁移:
rails generate paperclip Answer diagram 查看示例here. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |