質問編集履歴
2
routesも追加しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -340,6 +340,46 @@
|
|
340
340
|
|
341
341
|
|
342
342
|
|
343
|
+
```routes
|
344
|
+
|
345
|
+
Rails.application.routes.draw do
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
root 'posts#index'
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
devise_for :users, :controllers => {
|
354
|
+
|
355
|
+
:registrations => 'users/registrations',
|
356
|
+
|
357
|
+
:sessions => 'users/sessions'
|
358
|
+
|
359
|
+
}
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
devise_scope :user do
|
364
|
+
|
365
|
+
get 'users/:id/edit' => 'users/registrations#edit', as: :user_edit
|
366
|
+
|
367
|
+
end
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
resources :posts
|
372
|
+
|
373
|
+
resources :comments, only: %i[create destroy]
|
374
|
+
|
375
|
+
resources :testsessions, only: :create
|
376
|
+
|
377
|
+
resources :users, only: %i[show update edit]
|
378
|
+
|
379
|
+
end
|
380
|
+
|
381
|
+
```
|
382
|
+
|
343
383
|
|
344
384
|
|
345
385
|
データベースがぐちゃぐちゃなのは承知です。
|
1
controllerのコードを追加しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -216,6 +216,132 @@
|
|
216
216
|
|
217
217
|
|
218
218
|
|
219
|
+
```users
|
220
|
+
|
221
|
+
class UsersController < ApplicationController
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
def show
|
226
|
+
|
227
|
+
@user = User.find(params[:id])
|
228
|
+
|
229
|
+
end
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
# def new
|
234
|
+
|
235
|
+
# end
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
def edit
|
240
|
+
|
241
|
+
@user = User.find(params[:id])
|
242
|
+
|
243
|
+
end
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
def update
|
248
|
+
|
249
|
+
@user = User.find(params[:id])
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
if @user.update(user_params)
|
254
|
+
|
255
|
+
flash[:success] = "プロフィールを更新しました"
|
256
|
+
|
257
|
+
redirect_to user_path
|
258
|
+
|
259
|
+
else
|
260
|
+
|
261
|
+
render user_edit_path
|
262
|
+
|
263
|
+
end
|
264
|
+
|
265
|
+
end
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
private
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
def user_params
|
274
|
+
|
275
|
+
params.require(:user).permit(:name, :email, :password,:password_confirmation)
|
276
|
+
|
277
|
+
end
|
278
|
+
|
279
|
+
end
|
280
|
+
|
281
|
+
```
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
```registrations
|
286
|
+
|
287
|
+
class Users::RegistrationsController < Devise::RegistrationsController
|
288
|
+
|
289
|
+
# before_action :configure_sign_up_params, only: [:create]
|
290
|
+
|
291
|
+
# before_action :configure_account_update_params, only: [:update]
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
def show
|
296
|
+
|
297
|
+
@user = User.find(params[:id])
|
298
|
+
|
299
|
+
end
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
def new
|
304
|
+
|
305
|
+
end
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
def create
|
310
|
+
|
311
|
+
super
|
312
|
+
|
313
|
+
#ユーザーが無事に作られていたらprofileを作成
|
314
|
+
|
315
|
+
if resource
|
316
|
+
|
317
|
+
#resource==user
|
318
|
+
|
319
|
+
profile = Profile.new
|
320
|
+
|
321
|
+
profile.user_id = resource.id
|
322
|
+
|
323
|
+
profile.name = params[:profile][:name]
|
324
|
+
|
325
|
+
profile.save
|
326
|
+
|
327
|
+
end
|
328
|
+
|
329
|
+
end
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
def edit
|
334
|
+
|
335
|
+
@user = User.find(params[:id])
|
336
|
+
|
337
|
+
end
|
338
|
+
|
339
|
+
```
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
|
344
|
+
|
219
345
|
データベースがぐちゃぐちゃなのは承知です。
|
220
346
|
|
221
347
|
|