Skip to content

Field Types Reference

All field types inherit from Terrazzo::Field::Base.

Base Field API

MethodDescription
#field_typeReturns the underscored type name (e.g., "string", "belongs_to")
#serialize_value(mode)Returns the serialized value for :index, :show, or :form mode
#serializable_optionsReturns a hash of options sent to the React component
#required?true if the model has a presence validator on this attribute
.searchable?Whether this field type supports search (default: false)
.sortable?Whether this field type supports sorting (default: true)
.eager_load?Whether to eager-load this association (default: false)
.with_options(opts)Returns a deferred field with merged options
.permitted_attributeReturns the attribute name for strong parameters

Field Types

TypeClassSearchableSortableEager Load
StringField::StringYesYesNo
TextField::TextYesYesNo
NumberField::NumberNoYesNo
BooleanField::BooleanNoYesNo
DateField::DateNoYesNo
DateTimeField::DateTimeNoYesNo
TimeField::TimeNoYesNo
EmailField::EmailYesYesNo
URLField::UrlNoYesNo
PasswordField::PasswordNoNoNo
SelectField::SelectNoYesNo
Rich TextField::RichTextYesNoNo
BelongsToField::BelongsToNoYesYes
HasManyField::HasManyNoYesNo
HasOneField::HasOneNoNoYes
PolymorphicField::PolymorphicNoNoNo
HstoreField::HstoreNoNoNo

Options by Field Type

String

  • truncate — max characters on index (default: 50)

Number

  • prefix — string prepended to display (e.g., "$")
  • suffix — string appended to display
  • decimals — number of decimal places

Select

  • collection — array, proc, or enum name

BelongsTo

  • scope — proc to filter available records
  • include_blank — whether to allow blank selection

Hstore

  • truncate — max characters for the index preview (default: 80)

Renders PostgreSQL hstore columns as interactive key-value pair editors. On the index page, values appear as a truncated comma-separated preview. On the show page, each key-value pair is displayed with the key as a badge. The form provides an add/remove row editor for key-value pairs.

ruby
ATTRIBUTE_TYPES = {
  metadata: Field::Hstore,
  settings: Field::Hstore.with_options(truncate: 50),
}

HasMany / HasOne

  • scope — proc to filter available records

Released under the MIT License.