-
Notifications
You must be signed in to change notification settings - Fork 183
Rich Validations
Scharrels edited this page Aug 5, 2015
·
13 revisions
To chain validations to one prerequisite.
validates :username, :password, presence: true do
validate :password_ok?
end
Allows more prerequisite validations and unlimited nesting.
group :syntax do
validates :email, :password, presence: true
validates :email, email: true # here, another validation that is not presence.
end
group :authentication, after: :syntax do # runs only if syntax is correct
validate :password_ok?
end
group :syntax, if: -> {} do
RememberMeSignIn < SignIn
group :more_syntax, next_to: :syntax do
validates :remember_me, :inclusion => {:in => [true, false]}
end
end
disable_group :validation