LoginSignup
0
0

More than 3 years have passed since last update.

authenticateメゾットについて。

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

user.authenticate(password)で
合っていればユーザーの情報を出す。
間違っていれば、falseを返すメゾット。

主にログイン等に使われる。

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

この文は&&の論理積(and)はnilとfalse以外は
Rubyではnilとfalse以外のすべてのオブジェクトは、真偽値ではtrueになるという性質を利用して、ログインできるかできないかをif文を使って実行している。

真偽値についての理解が浅かったため理解するのに時間がかかった。。。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0