[RUBY] About the authenticate method.

user = User.find_by(email: params[:session][:email].downcase)
    if user && user.authenticate(params[:session][:password])

with user.authenticate (password) If it matches, the user's information is given. A method that returns false if incorrect.

Mainly used for login etc.

if user && user.authenticate(params[:session][:password])

In this statement, the logical product (and) of && is other than nil and false. In Ruby, all objects other than nil and false use the property that the boolean value is true, and whether or not you can log in is executed using an if statement.

It took a long time to understand because the understanding of the boolean value was shallow. .. ..

Recommended Posts

About the authenticate method.
About the method
Output about the method # 2
About the length method
About the map method
About the ancestors method
About the to_s method.
about the where method (rails)
Consideration about the times method
About the role of the initialize method
About the package
About No Method Error
About the StringBuilder class
Commentary: About the interface
About the asset pipeline
About the function double-java
About Java method binding
About the ternary operator
About method splitting (Java)
About the Kernel module
[Output] About the database
About the [ruby] operator
About the handling of Null
About specifying the JAXRS path
What is the pluck method?
About the description of Docker-compose.yml
About the File :: Stat class
[Java Silver] About equals method
Understand the helper method form_with
About the same and equivalent
About the Android life cycle
About the programming language Crystal
About Rails scraping method Mechanize
What is the initialize method?
[Ruby] Questions and verification about the number of method arguments
How to use the link_to method
About the behavior of ruby Hash # ==
Simulate the simplex method with GUI
How to use the include? method
How to use the form_with method
About the basics of Android development
[Rails] About the Punk List function
About the equals () and hashcode () methods
About the symbol <%%> in Rails erb
About the information sharing app band
Java comparison using the compareTo () method
About the current development environment (Java 8)
I tried to explain the method
A murmur about the utility class
[Rails] About helper method form_with [Basic]
Think about the 7 rules of Optional
About =
[Rails 6] destroy using the resources method
Was that so, the user_signed_in? method
Summary about the introduction of Device
About the log level of java.util.logging.Logger
Call the super method in Java
About the continuous division method learned in the 4th grade of elementary school
My thoughts on the equals method (Java)
About the version of Docker's Node.js image
Guess about the 2017 Java Persistence Framework (3) Reladomo