0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

railsのsessionについて

Last updated at Posted at 2019-09-21

railsチュートリアルで、以下の部分の理解が甘かったので、自分なりに解釈してみました。

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

では、downcaseメソッドを使って、大文字を小文字にすべて変換させて、大文字小文字関係なく、メールアドレス自体が合っていたらokとしている(?)
入力されたメールアドレスから、Userモデルから該当するメールアドレスを持っているユーザーを検索して、見つけたらuserに代入する。

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

は、もし該当するメールアドレスを持っているユーザーがいて、かつ入力されたパスワードが合っていたら、、、という意味ではないかと解釈しました。

独学の身なので、もし間違った解釈をしている、もっとこう考えた方がいい、という方がいらっしゃいましたら、、教えていただけると幸いです。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?