プログラミング学習サイトで勉強中です!よく意味が理解できない文法があったので、質問しています。
before_action :set_current_userは何の為にあるのでしょうか?
rails
1class ApplicationController < ActionController::Base 2 before_action :set_current_user 3 4 def set_current_user 5 @current_user = User.find_by(id: session[:user_id]) 6 end 7 8 def authenticate_user 9 if @current_user == nil 10 flash[:notice] = "ログインが必要です" 11 redirect_to("/login") 12 end 13 end 14end 15
私は authenticateメソッドで@current_userを使う為だと思っていたんですが、
当該の学習サイトで
とあり、わざわざ指定してなくて良いなら、何の為にあるのかわからず質問させていただきました。
よろしくお願いします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/12/04 07:57