开发者

ruby on rails 2.0+ scaffolding

My question is how do you find the "type" for a database column whats the difference between text / string. Is there anyway I can find this out?

script/generate scaffold ModelName field1:type field2:type field3:type
or
script/generate scaffold Post title:string body:text catego开发者_运维知识库ry_id:integer


Here is the list for mysql database

:binary     blob
:boolean    tinyint(1)
:date     date
:datetime   datetime
:decimal    decimal
:float   float
:integer    int(11)
:string     varchar(255)
:text     text
:time     time
:timestamp  datetime


To get types for a DB column in MYSQL run:

desc table_name

In the Rails Console, run Model.inspect to get types for the corresponding table attrs:

 Studio.inspect
=> "Studio(id: integer, name: string, subdomain: string, workdays_mask: integer, created_by: integer, created_at: datetime, updated_at: datetime, workhours: text, template_styles: text, contact_info: text)"


The underlying types really depend on the database itself (and the Rails db driver implementation), but for MySQL:

String: VARCHAR default to a length of 255 - the MySQL default - unless you provide a length/size(?) value.

Text: TEXT or LONGTEXT (http://dev.mysql.com/doc/refman/5.0/en/blob.html)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜