Ruby on Rails - confirmation of attribute in ruby on rails - ruby on rails tutorial - rails guides - rails tutorial - ruby rails
We should use this when we have two text fields that should receive exactly the same content.
Example
- We may want to confirm an email address or a password.
- This validation creates a virtual attribute whose name is the name of the field that has to be confirmed with _confirmation appended.
class Person < ApplicationRecord
validates :email, confirmation: true
end
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
Note: This check is performed only if email_confirmation is not nil.
Require Confirmation:
- Make sure to add a presence check for the confirmation attribute.
class Person < ApplicationRecord
validates :email, confirmation: true
validates :email_confirmation, presence: true
end