Rails Model Type List

Does anyone have a complete list of model types that are specified when creating model forests?

eg.

foo:string bar:text baz:boolean 

etc...

And what are these types mapped in terms of default UI elements? Text box, text area, radio button, checkbox, etc.

+83
ruby-on-rails
Jul 15 '10 at 21:45
source share
2 answers

Attributes are SQL types, so the following options are supported:

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

They are described in the column. in the Active Record API .

+205
Jul 15 '10 at 22:05
source share

In model forests you can use the following basic field types: they are all supported in ActiveRecord-supported databases without any additional gem (MySQL, PostgreSQL, SQLite):

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

In the scaffold generator, you can also declare external links using the field type :references , which additionally adds the belongs_to link to the new model.

If you use Rails 4 and PostgreSQL, you can take advantage of the following benefits:

  • :hstore
  • :array
  • :cidr_address
  • :ip_address
  • :mac_address

To display the user interface (data type of the model type → HTML), the following image has all the main field types:

Rails data types, scaffolding HTML mapping

+36
Jan 22 '14 at 2:39 on
source share



All Articles