質問編集履歴

1

当該コントローラ、メーラー部分を追記しました

2018/12/04 18:10

投稿

okamotchan_
okamotchan_

スコア10

test CHANGED
File without changes
test CHANGED
@@ -27,6 +27,8 @@
27
27
  ### 該当のソースコード
28
28
 
29
29
 
30
+
31
+ development.rb(一部略)
30
32
 
31
33
  ```ruby
32
34
 
@@ -60,6 +62,86 @@
60
62
 
61
63
  ```
62
64
 
65
+ application_mailer.rb
66
+
67
+ ```
68
+
69
+ class ApplicationMailer < ActionMailer::Base
70
+
71
+ default from: 'from@example.com'
72
+
73
+ layout 'mailer'
74
+
75
+ end
76
+
77
+ ```
78
+
79
+ application_controller.rb
80
+
81
+ ```
82
+
83
+ class ApplicationController < ActionController::Base
84
+
85
+ protect_from_forgery with: :exception, prepend: true
86
+
87
+ before_action :authenticate_user!
88
+
89
+
90
+
91
+ private
92
+
93
+
94
+
95
+ def current_user
96
+
97
+ return unless session[:user_id]
98
+
99
+ @current_user ||= User.find(session[:user_id])
100
+
101
+ end
102
+
103
+
104
+
105
+ def logged_in?
106
+
107
+ !!session[:user_id]
108
+
109
+ end
110
+
111
+
112
+
113
+ def authenticate
114
+
115
+ return if logged_in?
116
+
117
+ redirect_to root_path, alert: "ログインしてください"
118
+
119
+ end
120
+
121
+
122
+
123
+ before_action :configure_permitted_parameters, if: :devise_controller?
124
+
125
+
126
+
127
+ protected
128
+
129
+
130
+
131
+ def configure_permitted_parameters
132
+
133
+ added_attrs = [:name, :email, :password, :password_confirmation, :remenber_me]
134
+
135
+ devise_parameter_sanitizer.permit :sign_up, keys: added_attrs
136
+
137
+ devise_parameter_sanitizer.permit :account_update, keys: added_attrs
138
+
139
+ end
140
+
141
+ end
142
+
143
+ ```
144
+
63
145
 
64
146
 
65
147
  ### 試したこと