consider scenario,
User model with name, birth_date fields
(here birth_date is not mandatory field)
inside view form birth_date is assigned as '31/31/1985' which is invalid
ideally user object should be invalid and while save raise an error on birth_date field but that's not happening and user object gets saved with birth_date as blank which is completely misleading.
After debugging found that while assigning attributes birth_date value it gets assigned as blank and as birth_date is optional object gets saved.
class User < ActiveRecord::Base
def initialize(args={})
logger.info args[:birth_date] #invalid value comes upto here but vanishes afterwords
super
end
end
Any clue how to get validation working properly for not mandatory date fields ??
No comments:
Post a Comment