I’m learning rails, and ruby.
I was looking at this bcrypt tutorial and have some questions in mind.
1.
class User < ActiveRecord::Base
has_secure_password
validates :password,
:length => { :minimum => 5 }
end
What is
has_secure_password
and
validates :password, :length => { :minimum => 5 }
called? Are they just a function call?
2.
I was trying to read the source of bcrypt to see how the above validates links back to the source, but I couldn’t find anything on it.
3.
What is the meaning of
validates_confirmation_of :password, if: ->{ password.present? }
in this line ?
resting:
I’m learning rails, and ruby.
I was looking at this bcrypt tutorial and have some questions in mind.
1.
class User < ActiveRecord::Base
has_secure_password
validates :password,
:length => { :minimum => 5 }
end
What is
has_secure_password
and
validates :password, :length => { :minimum => 5 }
called? Are they just a function call?
has_secure_password is a Rails method.(See: http://api.rubyonrails.org/classes/ActiveModel/SecurePassword/ClassMethods.html ) validates is also a Rails method.
Validates is a Rails method, so you won’t be finding anything in bcrypt. Have a look here: http://edgeguides.rubyonrails.org/active_record_validations.html
This is a check to see if two passwords match. For example on a sign up form where you ask the user to create a password and, in a subsequent field, ask them to confirm their password.