質問編集履歴

1

情報追加

2020/10/24 09:57

投稿

divclass123
divclass123

スコア35

test CHANGED
File without changes
test CHANGED
@@ -16,7 +16,11 @@
16
16
 
17
17
  とのエラーが出ていて、
18
18
 
19
+ ググったとこと、、Ruby(Net::HTTP?)が SSL証明書を見つけることができなくて、HTTPS 接続に失敗しているのが原因らしい,SSL証明書が必要?な気がする
20
+
21
+
22
+
19
- ググったとこと、SSL証明書必要?な気が
23
+ ユーザーを新規登録する際にエラー出ま
20
24
 
21
25
 
22
26
 
@@ -222,6 +226,228 @@
222
226
 
223
227
  ```
224
228
 
229
+
230
+
231
+ ```ruby
232
+
233
+ #users_controller.rb
234
+
235
+
236
+
237
+ class UsersController < ApplicationController
238
+
239
+ before_action :logged_in_user,only: [:index,:edit,:update,:destroy]
240
+
241
+ # メソッド名は基本シンボルで呼び出す
242
+
243
+ # 一回before_actionをコメントアウトして
244
+
245
+ # テストかけてちゃんと失敗するか確かめるべき
246
+
247
+ before_action :correct_user, only: [:edit,:update]
248
+
249
+ before_action :admin_user, only: :destroy
250
+
251
+
252
+
253
+ # => GET /users
254
+
255
+ def index
256
+
257
+ @users = User.paginate(page: params[:page])
258
+
259
+ # pageの中にpageが格納されていて、何番目
260
+
261
+ # のページにいるか取得できる
262
+
263
+ end
264
+
265
+
266
+
267
+ def show
268
+
269
+ @user = User.find(params[:id])
270
+
271
+ end
272
+
273
+
274
+
275
+ def new
276
+
277
+ @user = User.new
278
+
279
+ end
280
+
281
+
282
+
283
+ def create
284
+
285
+ @user = User.new(user_params)
286
+
287
+ if @user.save
288
+
289
+ # before_createでトークンがセットされてる
290
+
291
+ # => メールオブジェクトを生成する条件は
292
+
293
+ # 整ってる
294
+
295
+ UserMailer.account_activation(@user).deliver_now
296
+
297
+ # メイラーメソッド呼び出し
298
+
299
+ # deliver_nowは送信するメソッド
300
+
301
+ # 引数に渡されたユーザーに対して送信できるのかな?
302
+
303
+ flash[:info] = "Please check your email to activate your account."
304
+
305
+ redirect_to root_url
306
+
307
+ # log_in @user
308
+
309
+ # flash[:success] = "Welcome to the Sample App!!"
310
+
311
+ # redirect_to @user
312
+
313
+ # # user_path(@user)
314
+
315
+ # # user_path(@user.id)
316
+
317
+ # # user_path(1) => /users/1
318
+
319
+ else
320
+
321
+ render 'new'
322
+
323
+ end
324
+
325
+ end
326
+
327
+
328
+
329
+ # GET /users/:id/edit
330
+
331
+ def edit
332
+
333
+ @user = User.find(params[:id])
334
+
335
+ # => app/views/users/edit.html.erb
336
+
337
+ end
338
+
339
+
340
+
341
+ # PATCH /users/:id
342
+
343
+ def update
344
+
345
+ @user = User.find(params[:id])
346
+
347
+ if
348
+
349
+ @user.update(user_params)
350
+
351
+ flash[:success] = "Profile update"
352
+
353
+ redirect_to @user
354
+
355
+ else
356
+
357
+ render 'edit'
358
+
359
+ end
360
+
361
+ end
362
+
363
+
364
+
365
+ def destroy
366
+
367
+ User.find(params[:id]).destroy
368
+
369
+ flash[:success] = "User deleted"
370
+
371
+ redirect_to users_url
372
+
373
+ end
374
+
375
+
376
+
377
+ private
378
+
379
+ # これよりしたに書いたメソッドはこのファイルの
380
+
381
+ # 外からアクセスできない(基本的に)
382
+
383
+
384
+
385
+ def user_params
386
+
387
+ params.require(:user).permit(:name,:email,:password,:password_confirmation)
388
+
389
+ end
390
+
391
+
392
+
393
+ # ログインしてなかったらログインページに遷移する
394
+
395
+ def logged_in_user
396
+
397
+ unless logged_in?
398
+
399
+ # ログインしてるかどうか確かめるメソッド
400
+
401
+ store_location
402
+
403
+ # 遷移したいページを覚えとく
404
+
405
+ flash[:danger] = "Please log in."
406
+
407
+ redirect_to login_url
408
+
409
+ end
410
+
411
+ end
412
+
413
+
414
+
415
+ def correct_user
416
+
417
+ @user = User.find(params[:id])
418
+
419
+ redirect_to(root_url) unless current_user?(@user)
420
+
421
+ # current_user?メソッド呼び出し
422
+
423
+ # form_withから受け取ったパラメーターのuserと
424
+
425
+ # セッションまたは、クッキーからのユーザー
426
+
427
+ # が一致してるかしてないか
428
+
429
+
430
+
431
+ end
432
+
433
+
434
+
435
+ def admin_user
436
+
437
+ redirect_to(root_url) unless current_user.admin?
438
+
439
+ end
440
+
441
+ end
442
+
443
+
444
+
445
+
446
+
447
+
448
+
449
+ ```
450
+
225
451
  ### 試したこと
226
452
 
227
453
 
@@ -232,7 +458,41 @@
232
458
 
233
459
  上記の記事を参考にしたところ、記事通りの挙動はしましたが結果は変わらずでした
234
460
 
235
-
461
+ ```
462
+
463
+ $ wget http://curl.haxx.se/ca/cacert.pem
464
+
465
+ ```
466
+
467
+ 上記のコマンドで一応SSL証明書は手に入れた、、??
468
+
469
+
470
+
471
+ https://stackoverflow.com/questions/4528101/ssl-connect-returned-1-errno-0-state-sslv3-read-server-certificate-b-certificat
472
+
473
+ 上記の記事を参考にしたところ
474
+
475
+ ```
476
+
477
+ SSL_CERT_FILE=/opt/local/etc/certs/cacert.pem rails generate jquery:install
478
+
479
+ ```
480
+
481
+ を実行したら
482
+
483
+ ```
484
+
485
+ Running via Spring preloader in process 3195
486
+
487
+ Could not find generator 'jquery:install'.
488
+
489
+ Run `rails generate --help` for more options.
490
+
491
+ ```
492
+
493
+
494
+
495
+ と出てきました、、
236
496
 
237
497
  ### 補足情報(FW/ツールのバージョンなど)
238
498