質問編集履歴
3
users_controller.rbの編集
test
CHANGED
File without changes
|
test
CHANGED
@@ -100,6 +100,28 @@
|
|
100
100
|
|
101
101
|
```
|
102
102
|
|
103
|
+
def show
|
104
|
+
|
105
|
+
@user = User.find(params[:id])
|
106
|
+
|
107
|
+
if @user != current_user
|
108
|
+
|
109
|
+
redirect_to root_url
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
def edit
|
118
|
+
|
119
|
+
@user = current_user
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
|
103
125
|
def update
|
104
126
|
|
105
127
|
@user = current_user
|
2
sessionsコントローラ、ログインページのコードroutes.rbの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -28,7 +28,7 @@
|
|
28
28
|
|
29
29
|
|
30
30
|
|
31
|
-
### 関連
|
31
|
+
### 関連しそうなソースコード
|
32
32
|
|
33
33
|
#####app/views/users/edit.html.erb
|
34
34
|
|
@@ -182,6 +182,198 @@
|
|
182
182
|
|
183
183
|
|
184
184
|
|
185
|
+
####app/views/devise/registrations/new.html.erb(ログインページのコード)
|
186
|
+
|
187
|
+
```
|
188
|
+
|
189
|
+
<h2>Sign up</h2>
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
|
194
|
+
|
195
|
+
<%= render "devise/shared/error_messages", resource: resource %>
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
<div class="field">
|
200
|
+
|
201
|
+
<h7>名前</h7><br>
|
202
|
+
|
203
|
+
<%= f.text_field :username %>
|
204
|
+
|
205
|
+
</div>
|
206
|
+
|
207
|
+
<div class="field">
|
208
|
+
|
209
|
+
<h7>メールアドレス</h7><br>
|
210
|
+
|
211
|
+
<%= f.email_field :email, autofocus: true, autocomplete: "email" %>
|
212
|
+
|
213
|
+
</div>
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
<div class="field">
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
<h7>パスワード(6文字以上)</h7><br>
|
222
|
+
|
223
|
+
<%= f.password_field :password, autocomplete: "new-password" %>
|
224
|
+
|
225
|
+
</div>
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
<div class="field">
|
230
|
+
|
231
|
+
<h7>確認用パスワード</h7><br>
|
232
|
+
|
233
|
+
<%= f.password_field :password_confirmation, autocomplete: "new-password" %>
|
234
|
+
|
235
|
+
</div>
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
<div class="actions">
|
240
|
+
|
241
|
+
<%= f.submit "Sign up" %>
|
242
|
+
|
243
|
+
</div>
|
244
|
+
|
245
|
+
<% end %>
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
<%= render "devise/shared/links" %>
|
250
|
+
|
251
|
+
```
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
####app/controllers/users/sessions_controller.rb(deviseのコントローラ)
|
256
|
+
|
257
|
+
```
|
258
|
+
|
259
|
+
# frozen_string_literal: true
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
class Users::SessionsController < Devise::SessionsController
|
264
|
+
|
265
|
+
# before_action :configure_sign_in_params, only: [:create]
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
# GET /resource/sign_in
|
270
|
+
|
271
|
+
# def new
|
272
|
+
|
273
|
+
# super
|
274
|
+
|
275
|
+
# end
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
# POST /resource/sign_in
|
280
|
+
|
281
|
+
# def create
|
282
|
+
|
283
|
+
# super
|
284
|
+
|
285
|
+
# end
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
# DELETE /resource/sign_out
|
290
|
+
|
291
|
+
# def destroy
|
292
|
+
|
293
|
+
# super
|
294
|
+
|
295
|
+
# end
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
# protected
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
# If you have extra params to permit, append them to the sanitizer.
|
304
|
+
|
305
|
+
# def configure_sign_in_params
|
306
|
+
|
307
|
+
# devise_parameter_sanitizer.permit(:sign_in, keys: [:attribute])
|
308
|
+
|
309
|
+
# end
|
310
|
+
|
311
|
+
end
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
```
|
316
|
+
|
317
|
+
####routes.rb
|
318
|
+
|
319
|
+
```
|
320
|
+
|
321
|
+
Rails.application.routes.draw do
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
devise_for :admin_users, ActiveAdmin::Devise.config
|
326
|
+
|
327
|
+
ActiveAdmin.routes(self)
|
328
|
+
|
329
|
+
resources :reactions
|
330
|
+
|
331
|
+
get 'answers' => 'answers#index'
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
resources :questions, shallow: true do
|
336
|
+
|
337
|
+
resources :answers, shallow: true do
|
338
|
+
|
339
|
+
resources :reactions
|
340
|
+
|
341
|
+
end
|
342
|
+
|
343
|
+
end
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
devise_for :users, controllers: { omniauth_callbacks: 'omniauth_callbacks' ,
|
348
|
+
|
349
|
+
registrations: 'users/registrations',
|
350
|
+
|
351
|
+
sessions: 'users/sessions'
|
352
|
+
|
353
|
+
}
|
354
|
+
|
355
|
+
get 'users/show', to: 'users#show'
|
356
|
+
|
357
|
+
resources :users
|
358
|
+
|
359
|
+
resource :user, except: [:new, :create, :destroy]
|
360
|
+
|
361
|
+
root 'questions#index'
|
362
|
+
|
363
|
+
get 'pages/index'
|
364
|
+
|
365
|
+
get 'pages/show'
|
366
|
+
|
367
|
+
get 'questions', to:'questions#index'
|
368
|
+
|
369
|
+
end
|
370
|
+
|
371
|
+
```
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
|
376
|
+
|
185
377
|
### 試したこと
|
186
378
|
|
187
379
|
|
1
タイトルの変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ユーザー情報をUPDATE後にログインセッションが切れるのを解消したい
|
1
|
+
[Rails6]ユーザー情報をUPDATE後にログインセッションが切れるのを解消したい
|
test
CHANGED
File without changes
|