Hi
I wrote the following validation in my model (using Rails 2.1)
validates_each :checker :do |record, attr, value|
record.errors.add attr, :existing_checkin_out if value == 0
end , :on => :update, :if => :checker_required?
obviously I got an error as I don’t know where to write the :on
and :if options … (I also tried many other way …)
1- how can I write them in validates_each ?
2- is there any better validation procedure, on UPDATE only, for
this ‘checker’ field (value is 0 or 1)
if the field is updated to 0 (changing the status to non-checker…)
I want to add an error
ONLY when checker state 1 is still mandatory (checker_required? =>
true)
(some planned or confirmed checkins or checkouts instances are still
depending upon this user)
here is my checker_required? proc
protected
def checker_required?
checks = self.checkins + self.checkouts
return false if checks.empty?
checks.map {|c| c[:id] if c.planned? ||
c.confirmed? }.compact.empty? ? false : true
end
thanks for your lights …