如何使用&QUOT产生支架的数据类型;额外的描述"在Rails 3的? [英] How to generate scaffold for data type with "extra description" in Rails 3?

查看:116
本文介绍了如何使用&QUOT产生支架的数据类型;额外的描述"在Rails 3的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从<一个href="http://stackoverflow.com/questions/1019939/ruby-on-rails-best-method-of-handling-currency-money">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,红宝石1.92

Working in Rails 3.07, Ruby 1.92

推荐答案

在Rails 3.1 及以下,语法

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}

另注:如果您在使用bash 的Mac OS X 10.9 尝试,而不是逗号点

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}

这篇关于如何使用&QUOT产生支架的数据类型;额外的描述&QUOT;在Rails 3的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆