1
0

sign-up前やログイン前に記述するbefore~~

Posted at

アプリのコントローラーは各コントローラー名の前にapplication_controllerを通ってから処理をしていく。

そのためbefore~~はこのapplication_controllerの中に記述する。

before_action :authenticate_user!

上記の意味は

ログインしていないユーザーをログインページの画面に促すことができる。

before_action :configure_permitted_parameters, if: :devise_controller?

 private
 def configure_permitted_parameters
   devise_parameter_sanitizer.permit(:sign_up, keys: [:name])
 end

deviseを使った新規登録をする際に使用。

例えば新規登録でemail,passwordだけでなく名前を追加で新規登録させたい場合に使う。(email,passwordはデフォルトで入っているので記述の必要はなし)permit下の処理名一覧
Image from Gyazo

1
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
1
0