multipart-message nevyn bengtsson's blog

featured articles 🦄, about, archive, tags

ruby script/generate scaffold < types

script/generate scaffold ModelName [field:type, field:type]

Rails 2.x changed the scaffolding script to one that doesn’t make a view that iterates over all the columns, letting you create an admin interface in five minutes, but rather one that wants you to fill in the types of all the columns of the table there, on the spot. (Can you tell I don’t like the change?). Neither the in-command help, nor the docs on scaffold, nor google tell you what the valid types for the columns are; turns out it’s the same types you use in migrations. (Maybe that’s obvious, but being the foolish man I am, I never learned migrations properly until very recently). Thusly, I’ll copy-paste this wonderful cheat-sheet with the types, for future reference for myself and you:

Railsdb2mysqlopenbaseOracle
:binaryblob(32678)blobobjectblob
:booleandecimal(1)tinyint(1)booleannumber(10)
:datedatedatedatedate
:datetimetimestampdatetimedatetimedate
:decimaldecimaldecimaldecimaldecimal
:floatfloatfloatfloatnumber
:integerintint(11)integernumber(38)
:stringvarchar(255)varchar(255)char(4096)varchar2(255)
:textclob(32768)texttextclob
:timetimetimetimedate
:timestamptimestampdatetimetimestampdate
 
Rails postgresql sqlite sqlserver Sybase
:binarybyteablobimageimage
:booleanbooleanbooleanbitbit
:datedatedatedatetimedatetime
:datetimetimestampdatetimedatetimedatetime
:decimaldecimaldecimaldecimaldecimal
:floatfloatfloatfloat(8)float(8)
:integerintegerintegerintint
:string*varchar(255)varchar(255)varchar(255)
:texttexttexttexttext
:timetimedatetimedatetimetime
:timestamptimestampdatetimedatetimetimestamp

Tagged