Skip to content

Instantly share code, notes, and snippets.

@paulsonkoly
Created January 22, 2020 16:59
Show Gist options
  • Select an option

  • Save paulsonkoly/8a1509775fb93b95381a1d84f5bc2e8b to your computer and use it in GitHub Desktop.

Select an option

Save paulsonkoly/8a1509775fb93b95381a1d84f5bc2e8b to your computer and use it in GitHub Desktop.
validators
require 'active_support'
require 'active_model'
class X
include ActiveModel::Validations
include ActiveModel::Attributes
attribute :blah
validates :blah, numericality: { greater_than_or_equal_to: 0 }
validates :blah, numericality: { greater_than_or_equal_to: 3 }
end
x = X.new
x.blah = -1
x.valid? # => false
x.errors.full_messages # => ["Blah must be greater than or equal to 0", "Blah must be greater than or equal to 3"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment