チュートリアルでのユーザー作成時の処理まとめ
Ruby on Rails チュートリアル:実例を使って Rails を学ぼう 11章でのアカウント有効化メール関連の処理まとめ
1.ユーザーが新規登録をする (/usersへpost)
2.users_controllerのcreateアクションへ
3.before_createで設定したcreate_activation_digestメソッドの実行によりactivation_token,activation_digestへの入力
4.Userクラスのインスタンスの作成、データベースへの登録、UserMailerクラスのaccount_activationメソッドを利用したアカウント有効化メールの作成、送信(UserMailer.account_activation(@user).deliver_now)
5.ユーザーのクリックによりedit_account_activation_url(/account_activations/:id/edit) にgetが送られる(idにはactivation_token、クエリパラメータにはユーザーのメールアドレスが含まれる)
6.account_activations_controllerのeditアクションへ
7.params[:id]でactivation_token,params[:email]でクエリパラメータのメールアドレスを取得できるので、それを利用してユーザーの認証(authenticated?メソッドの実行)、activated属性、activated_at属性の変更、ユーザーのログイン処理が行われる