For anyone else searching for this, the PR has been moved to rails 5. My hack is to include ActiveRecord::AttributeAssignment
# works on my AR v4.2.4
class MyObj
include ActiveModel::Model
include ActiveRecord::AttributeAssignment
attr_accessor :my_date
def initialize(*params)
assign_attributes(*params)
end
# AttributeAssignment needs to know the class
def type_for_attribute(name)
case name
when 'my_date'
klass = Date
end
OpenStruct.new(klass: klass)
end
end
obj = MyObj.new('my_date(1i)' => '2015', 'my_date(2i)' => '1', 'my_date(3i)' => '31')
obj.my_date # Sat, 31 Jan 2015
For anyone else searching for this, the PR has been moved to rails 5. My hack is to include ActiveRecord::AttributeAssignment