Ruby-on-rails Rails 模型类型列表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3260345/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
List of Rails Model Types
提问by Gordon Potter
Does someone have a complete list of model types that be specified when generating a model scaffolding
有人有生成模型脚手架时指定的模型类型的完整列表吗
e.g.
例如
foo:string
bar:text
baz:boolean
etc...
等等...
And what do these types map to in terms of default UI elements? Text field, Text area, radio button, checkbox, etc...
这些类型在默认 UI 元素方面映射到什么?文本字段、文本区域、单选按钮、复选框等...
回答by Bayard Randel
The attributes are SQL types, hence the following are supported:
属性是 SQL 类型,因此支持以下类型:
:binary:boolean:date:datetime:decimal:float:integer:primary_key:string:text:time:timestamp
:binary:boolean:date:datetime:decimal:float:integer:primary_key:string:text:time:timestamp
These are documented under columnin the Active Record API.
这些记录下的列中活动记录API。
回答by Edu Lomeli
You can use the following basicfield types in model scaffolding, all are supported in ActiveRecord supported databases without any extra gem (MySQL, PostgreSQL, SQLite):
您可以在模型脚手架中使用以下基本字段类型,在 ActiveRecord 支持的数据库中都支持,无需任何额外的 gem(MySQL、PostgreSQL、SQLite):
:binary:boolean:date:datetime:decimal:float:integer:primary_key:string:text:time:timestamp
:binary:boolean:date:datetime:decimal:float:integer:primary_key:string:text:time:timestamp
In the scaffold generator you can also declare the foreign references using :referencesfield type, which additionaly adds a belongs_toreference in the new model.
在脚手架生成器中,您还可以使用:references字段类型声明外部引用,这会belongs_to在新模型中额外添加一个引用。
If you use Rails 4 and PostgreSQL, you can take advantage of these:
如果你使用 Rails 4 和 PostgreSQL,你可以利用这些:
:hstore:array:cidr_address:ip_address:mac_address
:hstore:array:cidr_address:ip_address:mac_address
For UI mapping (Model scaffold data type -> HTML), the next image has all the basicfield types:
对于 UI 映射(模型脚手架数据类型 -> HTML),下图包含所有基本字段类型:



