I have a simple model:
class Person < ActiveRecord::Base
def dob=(dobstr)
raise "oops"
end
def virtualdob=
raise "virtual oops"
end
end
dob is a table column. When I try to set it from a view, it correctly crashes ... but when I try to set it via the rails console, it never gets called... but calling the virtual attribute does raise the error.
>> a=Person.first ...... >> a.virtualdob="d" RuntimeError: virtual oops from /...../app/models/person.rb:105:in `virtualdob=' from (irb):7 >> a.dob="f" => "f"
I want to override dob= to use Chronic to parse date in a more forgiving manner, before validations. Making a different attribute is not acceptable, as views such as the rest_in_place plugin need the orginal attribute name.