尝试生成模型产品时DB中的错误

时间:2015-03-03 17:57:17

标签: ruby-on-rails ruby-on-rails-4

我将通过本教程在轨道上创建一个小型购物车系统:http://richonrails.com/articles/building-a-shopping-cart-in-ruby-on-rails

当我跑步时:

rails g model Product name price:decimal{12,3} active:boolean

然后运行rake db:migrate但是出现以下错误:

== 20150303175421 CreateProducts: migrating ===================================
-- create_table(:products)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

undefined method `decimal12' for #<ActiveRecord::ConnectionAdapters::TableDefinition:0x00000006a0fd10>/home/ubuntu/workspace/db/migrate/20150303175421_create_products.rb:5:in `block in change'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/schema_statements.rb:198:in `create_table'

有任何帮助吗?无法在任何地方搞清楚......

由于

2 个答案:

答案 0 :(得分:1)

documentation中所述,您需要将十进制字段描述放在引号中,否则rails会混淆并生成两个字段。

rails g model Product name 'price:decimal{12,3}' active:boolean

答案 1 :(得分:0)

未定义的方法`decimal12&#39;为#

rails g model Product name 'price:decimal{12,3}' active:boolean

您需要在控制台上以这种方式传递:http://edgeguides.rubyonrails.org/active_record_migrations.html#creating-a-standalone-migration