Validates_presence_of with validates_each dont work together

Hi there
how do I make validates_presence_of and validates each work?
here is my code

#validates_presence_of :quantity
#validates_numericality_of :quantity

validates_each :quantity do |record, attr, value|
if value < User.find(:first, :conditions => [‘id = ?’,
record.user_id]).minimumbottles
@min = User.find(:first, :conditions => [‘id = ?’,
record.user_id]).minimumbottles
record.errors.add attr, ‘=> ’ + @min.to_s + ’ is your minimum
order quantity for
the current program, please contact admin to change program
details’
end
end

but if I use validates_each validates_presence_of doesnot work
and I would like to use both
any help with very appreciated

I forgot to mention
I saw the :allow_nil option in the api docs but I dont know how to use
it
in my case

You could add an if statement to the top of your validates_each block as
such to emulate what validates_presence_of does eg:

validates_each :quantity do |model, attr, value|
if value.blank?
model.errors.add(attr, “can’t be blank”)

elsif value < User.find(:first, :conditions => [‘id = ?’,
record.user_id]).minimumbottles

end
end

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs