method

attribute

Importance_1
Ruby on Rails latest stable (v7.1.3.2) - 0 notes - Class: ClassMethods
attribute(name, ...) public

Defines a model attribute. In addition to the attribute name, a cast type and default value may be specified, as well as any options supported by the given cast type.

class Person
  include ActiveModel::Attributes

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

person = Person.new
person.name = "Volmer"

person.name   # => "Volmer"
person.active # => true
Show source
Register or log in to add new notes.