Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 datatypes?

People also ask

What are data types in Ruby on Rails?

Data types in Ruby represents different types of data like text, string, numbers, etc. All data types are based on classes because it is a pure Object-Oriented language.

What are models in Rails?

A Rails Model is a Ruby class that can add database records (think of whole rows in an Excel table), find particular data you're looking for, update that data, or remove data. These common operations are referred to by the acronym CRUD--Create, Remove, Update, Destroy.

What are the scalar types in Ruby?

There are two categories of scalar types: numeric�s and character strings. Numeric and String Literals All numeric data types in Ruby are descendants of the Numeric class. The immediate child classes of Numeric are Float and Integer. The Integer class has two child classes: Fixnum and Bignum.


Here are all the Rails3 (ActiveRecord migration) datatypes:

:binary
:boolean
:date
:datetime
:decimal
:float
:integer
:primary_key
:references
:string
:text
:time
:timestamp

Source


It is important to know not only the types but the mapping of these types to the database types, too:

enter image description here

enter image description here

For, example, note that in MS SQL Server we are using:

  1. the old "datetime" instead "datetime2"
  2. decimal with its default precision
  3. text and varchar instead nvarchar
  4. int (not possible to use tiny int/small int/big int)
  5. image instead BLOB

Do you mean for defining active record migrations? or do you mean Ruby data types?

Here's a link that may help for creating migrations:

Orthogonal Thought - MySQL and Ruby on Rails datatypes


It might be helpful to know generally what these data types are used for:

  • binary - is for storing data such as images, audio, or movies.
  • boolean - is for storing true or false values.
  • date - store only the date
  • datetime - store the date and time into a column.
  • decimal - is for decimals.
  • float - is for decimals. (What's the difference between decimal and float?)
  • integer - is for whole numbers.
  • primary_key - unique key that can uniquely identify each row in a table
  • string - is for small data types such as a title. (Should you choose string or text?)
  • text - is for longer pieces of textual data, such as a paragraph of information.
  • time - is for time only
  • timestamp - for storing date and time into a column.

I hope that helps someone! Also, here's the official list: http://guides.rubyonrails.org/migrations.html#supported-types