Solution for: #35: validating date_select in rails
override assign_multiparameter_attributes
- kueda on April 15, 2009, 11:41 PM UTC
I ended up overriding assign_multiparameter_attributes to look for empty fields. Obviously, this will break non-date multiparam assignments, but I'm hoping that will be ok in my case.
In my model:
In my model:
def assign_multiparameter_attributes(pairs)
pair_values = Hash[pairs].values
if pair_values.collect(&:blank?).include?(true) &&
pair_values.collect(&:blank?).uniq.include?(false)
@incomplete_date = true
else
super(pairs)
end
end
def validate
if @incomplete_date
self.errors.add_to_base("The date you entered is incomplete!")
end
end