Active Model
Date Type
Attribute type for date representation. It is registered under the :date
key.
class Person
include ActiveModel::Attributes
attribute :birthday, :date
end
person = Person.new
person.birthday = "1989-07-13"
person.birthday.class # => Date
person.birthday.year # => 1989
person.birthday.month # => 7
person.birthday.day # => 13
String
values are parsed using the ISO 8601 date format. Any other values are cast using their to_date
method, if it exists.
Methods
Included Modules
Constants
ISO_DATE | = | /\A(\d{4})-(\d\d)-(\d\d)\z/ |
Instance Public methods
type()
📝 Source code
# File activemodel/lib/active_model/type/date.rb, line 30
def type
:date
end
🔎 See on GitHub
type_cast_for_schema(value)
📝 Source code
# File activemodel/lib/active_model/type/date.rb, line 34
def type_cast_for_schema(value)
value.to_fs(:db).inspect
end
🔎 See on GitHub