v7.1.3.2 - Show latest stable - 0 notes

Active Model Attributes

The Attributes module allows models to define attributes beyond simple Ruby readers and writers. Similar to Active Record attributes, which are typically inferred from the database schema, Active Model Attributes are aware of data types, can have default values, and can handle casting and serialization.

To use Attributes, include the module in your model class and define your attributes using the attribute macro. It accepts a name, a type, a default value, and any other options supported by the attribute type.


class Person
  include ActiveModel::Attributes

  attribute :name, :string
  attribute :active, :boolean, default: true

person = = "Volmer" # => "Volmer" # => true
Show files where this module is defined (1 file)
Register or log in to add new notes.