instance method
attribute
Ruby on Rails 7.1.6
Since v5.2.8.1Signature
attribute(name, cast_type = nil, default: nil, **options)
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
Parameters
-
namereq -
...req
Source
# File activemodel/lib/active_model/attributes.rb, line 59
def attribute(name, ...)
super
define_attribute_method(name)
end
Defined in activemodel/lib/active_model/attributes.rb line 59
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveModel::Attributes::ClassMethods