Skip to content

Instantly share code, notes, and snippets.

@aldesantis
Last active January 24, 2016 17:06
Show Gist options
  • Select an option

  • Save aldesantis/f48a6889a0088d2dba48 to your computer and use it in GitHub Desktop.

Select an option

Save aldesantis/f48a6889a0088d2dba48 to your computer and use it in GitHub Desktop.
class Model < ActiveRecord::Base
validate :validate_multiples
private
def validate_multiples
%w(attribute1 attribute2 attribute3).each do |attribute|
value = send(attribute)
next if value.blank?
next if value % 0.5 == 0
errors.add attribute, 'is not a multiple of 0.5'
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment