如何为具有“额外描述"的数据类型生成脚手架在 Rails 3 中? [英] How to generate scaffold for data type with "extra description" in Rails 3?
问题描述
来自 Ruby on Rails:处理货币的最佳方法/钱,您如何为以下内容生成脚手架:
From Ruby on Rails: best method of handling currency / money, how do you generate a scaffold for the folowing:
add_column :items, :price, :decimal, :precision => 8, :scale => 2
例如:
rails generate scaffold LineItem name:string
price:decimal {:precision => 8, :scale => 2}
另外,十进制类型的额外描述"的正确术语是什么?
Also, what is the correct term for "extra description" for the decimal type?
使用 Rails 3.07、Ruby 1.92
Working in Rails 3.07, Ruby 1.92
推荐答案
在 Rails 3.1 及以下版本中,语法为
In Rails 3.1 and below, the syntax is
rails generate scaffold LineItem name:string price:decimal
然后手动将小数属性添加到迁移文件中
and then manually add the decimal properties to the migration file
t.decimal :price, :precision => 8, :scale => 2
在Rails 3.2中,可以指定十进制属性
In Rails 3.2, one can specify the decimal properties
rails generate scaffold LineItem name price:decimal{8,2}
注意:如果您正在运行 ZSH,则语法需要使用连字符而不是逗号.
NOTE: If you are running ZSH, the syntax requires a hyphen instead of a comma.
rails generate scaffold LineItem name price:decimal{8-2}
另一个注意事项:如果您在 Mac OS X 10.9 下使用 bash,请尝试用点代替逗号
ANOTHER NOTE: If you are using bash under Mac OS X 10.9 try a dot instead of the comma
rails generate scaffold LineItem name price:decimal{8.2}
这篇关于如何为具有“额外描述"的数据类型生成脚手架在 Rails 3 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!