module ActiveModel::Validations
Just like `presence` except that it properly ignores allow_nil / allow_blank. This is how Rails 3.2 worked, but was changed in Rails 4. Mongoid 3 and 4 both
act like Rails 4, so this is useful there too.
Ensure two (or more) associations share a common parent
:allow_nil will not only allow the attribute/association to be nil, but also any of the :scope's.
eg: validates :user, grandparent: {scope: :org, parent: :realm}
validates :user_id, grandparent: {scope: [:phone, :address], parent: :account_id}
Attribute ordering
Ensures one value is greater or lesser than another (set of) value(s). The special value of :now will automatically become Time.now (without needing a lambda). Always skips over nil values; use :presence to validate those.
eg: validates :start_at, before: :finish_at
validates :start_at, before: {value_of: :finish_at, if: ... } validates :finish_at, after: [:start_at, :now] validates :finish_at, after: {values_of: [:start_at, :now], if: ... }
Ensure an attribute is generally formatted as a URL. If addressable/uri is
already loaded, will use it to parse IDN's.
eg: validates :website, url: true
validates :redis, url: {scheme: 'redis'} validates :database, url: {scheme: %w(postgres mysql)}
write-once, read-many
Allows a value to be set to a non-nil value once, and then makes it immutable. Combine with existence: true to accomplish the same thing as attr_readonly, except with error messages (instead of silently refusing to save the change).
eg: validates :user_id, write_once: true
Optionally refuses changing from nil => non-nil, always making field immutable.
eg: validates :source, write_once: {immutable_nil: true}