0

I am using

ActiveModel::Model 
ActiveModel::Attributes.

I noticed that the attributes method used in my form object (active model) does not allow :text type. I was wondering how I can setup attributes to mimic the below sql table?

create_table "teachers", force: :cascade do |t|
    t.string "name"
    t.text "credentials", default: [], array: true
    t.integer "age"
    t.boolean "working", default: false
    t.bigint "user_id"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.index ["user_id"], name: "index_cpas_on_user_id"
  end
Lefty
  • 535
  • 6
  • 20

1 Answers1

0

Just use attribute :my_attribute, :string.

There is no actual difference between how ActiveRecord treats casting VARCHAR columns (represented by the :string type) and TEXT columns.

The only difference is the SQL generated by the migration and thus what type of column is used for storing the actual information.

On Postgres for example both TEXT and VARCHAR columns have an upper limit of about 1GB, but VARCHAR(n) lets you set a lower arbitrary limit such as VARCHAR(255) - but there is no performance benefit to either and thus no advantage to using the TEXT type. This of course can vary depending on what RDBMS is in use.

See:

max
  • 96,212
  • 14
  • 104
  • 165