We build Web & Mobile Applications.
A quick tip - ActiveRecord provides a number of methods that allow you to access information about the underlying table columns for a model.
columns
Column
objects.columns_hash
columns
method but returns a Hash
using column names as keys and Column
objects as values.column_names
The Column
objects returned by columns
and columns_hash
can then be used to get information such as the data type and default values, for example:
User.columns_hash['email'].type
=> :string
User.columns_hash['email'].default
=> nil
User.columns_hash['email'].sql_type
=> "varchar(255)"