Сделал так:
class InetSklad < ActiveRecord::Base
validates :tovar_id, presence: true
validates :count, presence: true
validates :count, numericality: true
validates :count, numericality: { only_integer: true,greater_than: 0}
validate :validate_max_count_sklad_tovar, :if => Proc.new { |a| a.dependent_attributes_valid? }
def dependent_attributes_valid?
[:tovar_id, :count].each do |field|
self.class.validators_on(field).each { |v| v.validate(self) }
if self.errors.messages[field].present?
self.errors.messages[field]=[self.errors.messages[field][0]] if self.errors.messages[field].kind_of?(Array)
return false
end
end
return true
end
работает!
подсмотрел
тут