質問編集履歴

1

情報の追記

2022/10/03 10:58

投稿

jack20xx
jack20xx

スコア45

test CHANGED
File without changes
test CHANGED
@@ -21,6 +21,67 @@
21
21
  https://github.com/yasslab/sample_apps/tree/main/5_0/ch11
22
22
  ```
23
23
 
24
+ ### 10/3 追記
25
+ ご回答を受け、メールの再送信を行うためのコントローラーを追加し、入力されたメールアドレスからユーザー情報を引き出して、アカウントの有効化メールの再送ができるように試行錯誤していますが、新たなエラーが出ていますので追記させていただきます。
26
+ 新たに追加した機能周りに原因があると思うのですが、解決方法をお聞きできれば嬉しいです。
27
+ ### エラー内容
28
+ ```
29
+ ActionController::UrlGenerationError in ResendActivations#create
30
+
31
+ No route matches {:action=>"edit", :controller=>"account_activations", :email=>"#実際は入力されています", :id=>nil}, possible unmatched constraints: [:id]
32
+ ```
33
+ ### エラーに該当していると思われる箇所
34
+ 1. account_activation_html
35
+ 2. user_mailer.rb
36
+ 3. user.rb
37
+ 4. resend_activations_controller.rb
38
+ --------------------
39
+ 1. account_activation_html
40
+ ```
41
+ <%= link_to "Activate", edit_account_activation_url(@user.activation_token,
42
+ email: @user.email) %>
43
+ ```
44
+ 2. user_mailer.rb
45
+ ```
46
+ class UserMailer < ApplicationMailer
47
+
48
+ def account_activation(user)
49
+ @user = user
50
+ mail to: user.email, subject: "Account activation"
51
+ end
52
+ end
53
+ ```
54
+ 3. user.rb
55
+ ```
56
+ class User < ApplicationRecord
57
+
58
+ def send_activation_email
59
+ UserMailer.account_activation(self).deliver_now
60
+ end
61
+
62
+ end
63
+
64
+ ```
65
+ 4. resend_activations_controller.rb
66
+ ```
67
+ class ResendActivationsController < ApplicationController
68
+ def new
69
+ end
70
+
71
+ def create
72
+ @user = User.find_by(email: params[:resend_activation][:email].downcase)
73
+ if
74
+ @user.send_activation_email
75
+ flash[:info] = "Please check your email to activate your account."
76
+ redirect_to root_url
77
+ else
78
+ render 'resend'
79
+ end
80
+ end
81
+ end
82
+ ```
83
+
84
+
24
85
  ### コメント
25
86
  調べた限り、アカウント有効化メールの再送機能に関して取り扱ってる記事が極端に少なかったため、質問させていただきました。
26
87
  初学者のため、至らない部分があれば申し訳ございません。