Feature #775
Updated by Daniel Curtis over 8 years ago
{{>toc}}
There are many different types of data types used for database tables with Ruby on Rails, each different database backend having their own data types. This is just a simple list of generic data types used with ActiveRecord with Ruby on Rails.
h2. @:string@
* Limited to 255 characters (depending on DBMS)
* Use for short text fields (names, emails, etc)
---
h2. @:text@
* Unlimited length (depending on DBMS)
* Use for comments, blog posts, etc. General rule of thumb: if it's captured via textarea, use Text. For input using textfields, use string.
---
h2. @:integer@
* Whole numbers
---
h2. @:float@
* Decimal numbers stored with floating point precision
* Precision is fixed, which can be problematic for some calculations; generally no good for math operations due to inaccurate rounding.
---
h2. @:decimal@
* Decimal numbers stored with precision that varies according to what is needed by your calculations; use these for math that needs to be accurate
* See this post for examples and an in-depth explanation on the differences between floats and decimals.
---
h2. @:boolean@
* Use to store true/false attributes (i.e. things that only have two states, like on/off)
---
h2. @:binary@
* Use to store images, movies, and other files in their original, raw format in chunks of data called blobs
---
h2. @:date@
* Stores only a date (year, month, day)
---
h2. @:time@
* Stores only a time (hours, minutes, seconds)
---
h2. @:datetime@
* Stores both date and time
---
h2. @:timestamp@
* Stores both date and time
---
h1. Resources
* http://stackoverflow.com/questions/11889048/is-there-documentation-for-the-rails-column-types
* http://blog.ifyouseewendy.com/blog/2015/08/10/data-types-in-rails/
* http://stackoverflow.com/questions/17918117/rails-4-list-of-available-datatypes