Attributes 以mm/dd/YY格式获取日期,并使用rails 5 attibutes API存储到数据库中
在我的app/models/dob_type.rb之后,我继承了cast_type datetimeAttributes 以mm/dd/YY格式获取日期,并使用rails 5 attibutes API存储到数据库中,attributes,ruby-on-rails-5,Attributes,Ruby On Rails 5,在我的app/models/dob_type.rb之后,我继承了cast_type datetime class DobType < ActiveRecord::Type::Datetime def cast(value) old_format = value.split('/') new_format = old_format[2] + '-' + old_format[0] + '-' + old_format[1] super
class DobType < ActiveRecord::Type::Datetime
def cast(value)
old_format = value.split('/')
new_format = old_format[2] + '-' + old_format[0] + '-' + old_format[1]
super new_format
end
end
它给了我
uninitialized constant ActiveRecord::Type::Datetime
有出路吗?提前感谢。这应该是ActiveRecord::Type::DateTime而不是ActiveRecord::Type::DateTime吗
user = User.create({:name => 'Jr. Adam Joe', :dob => '01/05/2016'})
uninitialized constant ActiveRecord::Type::Datetime