instance method
attribute
Ruby on Rails 7.0.10
Since v5.2.8.1Signature
attribute(name, cast_type = nil, default: NO_DEFAULT_PROVIDED, **options)
No documentation comment.
Parameters
-
namereq -
cast_typeopt = nil -
defaultkey = NO_DEFAULT_PROVIDED -
optionskeyrest
Source
# File activemodel/lib/active_model/attributes.rb, line 19
def attribute(name, cast_type = nil, default: NO_DEFAULT_PROVIDED, **options)
name = name.to_s
cast_type = Type.lookup(cast_type, **options) if Symbol === cast_type
cast_type ||= attribute_types[name]
self.attribute_types = attribute_types.merge(name => cast_type)
define_default_attribute(name, default, cast_type)
define_attribute_method(name)
end
Defined in activemodel/lib/active_model/attributes.rb line 19
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveModel::Attributes::ClassMethods