Kyl*_*oon 8 ruby-on-rails paperclip ruby-on-rails-3.1
我想添加两个不同的附件字段.迁移失败了我使用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'
Run Code Online (Sandbox Code Playgroud)
迁移看起来像这样:
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
Run Code Online (Sandbox Code Playgroud)
该模型还引用了回形针添加的方法,应用程序运行正常,因此根本没有安装回形针.我甚至尝试在迁移中添加了需要'paperclip',但这根本没有帮助.
and*_*ell 11
为我创建的迁移不再使用t.has_attached_file术语,它实际上显式添加了列.将通过运行以下命令创建迁移:
rails generate paperclip Answer diagram
Run Code Online (Sandbox Code Playgroud)
看看这里的例子.
| 归档时间: |
|
| 查看次数: |
7568 次 |
| 最近记录: |