質問編集履歴

5

コントローラーの記述の修正

2020/10/31 08:17

投稿

kema
kema

スコア6

test CHANGED
File without changes
test CHANGED
@@ -224,7 +224,7 @@
224
224
 
225
225
  private
226
226
 
227
- def
227
+ def set_user
228
228
 
229
229
  @user = User.find(params[:follow_id])
230
230
 

4

コントローラーの記述の修正

2020/10/31 08:17

投稿

kema
kema

スコア6

test CHANGED
File without changes
test CHANGED
@@ -258,14 +258,10 @@
258
258
 
259
259
  def show
260
260
 
261
- @posts = Post.includes(:user).order("created_at DESC")
262
-
263
261
  @comment = Comment.new
264
262
 
265
263
  @comments = @post.comments.includes(:user).order("created_at DESC")
266
264
 
267
- user = User.find(params[:id])
268
-
269
265
  @user = User.find(params[:id])
270
266
 
271
267
  end

3

修正

2020/10/31 07:05

投稿

kema
kema

スコア6

test CHANGED
File without changes
test CHANGED
@@ -388,216 +388,220 @@
388
388
 
389
389
  ```
390
390
 
391
+ <% if user_signed_in? %>
392
+
391
- <% unless current_user == user %>
393
+ <% unless current_user == user %>
392
-
394
+
393
- <% if current_user.following?(user) %>
395
+ <% if current_user.following?(user) %>
394
-
396
+
395
- <%= form_for(current_user.relationships.find_by(follow_id: user.id), html: { method: :delete }) do |f| %>
397
+ <%= form_for(current_user.relationships.find_by(follow_id: user.id), html: { method: :delete }) do |f| %>
396
-
398
+
397
- <%= hidden_field_tag :follow_id, user.id %>
399
+ <%= hidden_field_tag :follow_id, user.id %>
398
-
400
+
399
- <%= f.submit 'Unfollow', class: 'btn btn-danger btn-block' %>
401
+ <%= f.submit 'Unfollow', class: 'btn btn-danger btn-block' %>
402
+
403
+ <% end %>
404
+
405
+ <% else %>
406
+
407
+ <%= form_for(current_user.relationships.build) do |f| %>
408
+
409
+ <%= hidden_field_tag :follow_id, user.id %>
410
+
411
+ <%= f.submit 'Follow', class: 'btn btn-primary btn-block' %>
412
+
413
+ <% end %>
400
414
 
401
415
  <% end %>
402
416
 
417
+ <% end %>
418
+
419
+ <% end %>
420
+
421
+ ```
422
+
423
+ ルーティング
424
+
425
+ ```
426
+
427
+ Rails.application.routes.draw do
428
+
429
+ devise_for :users, only: [:show]
430
+
431
+ devise_for :users, controllers: {
432
+
433
+ registrations: 'users/registrations'
434
+
435
+ }
436
+
437
+ root to: "posts#index"
438
+
439
+ resources :posts do
440
+
441
+ resources :comments, only: [:create, :destroy]
442
+
443
+ collection do
444
+
445
+ get 'search'
446
+
447
+ end
448
+
449
+ end
450
+
451
+ resources :users, only: [:show, :index, :search]
452
+
453
+ resources :relationships, only: [:create, :destroy]
454
+
455
+
456
+
457
+ end
458
+
459
+ ```
460
+
461
+ app/views/posts/show.html.erb
462
+
463
+ ```
464
+
465
+ <div class="container">
466
+
467
+ <div class="row">
468
+
469
+ <div class="col-md-8 offset-md-2">
470
+
471
+ <%= image_tag @post.image.variant(resize:'800x800').processed %>
472
+
473
+ <br>
474
+
475
+ <br>
476
+
477
+ <br>
478
+
479
+ <h1 class="text-center">
480
+
481
+ <strong><%= @post.title %></strong>
482
+
483
+ </h1>
484
+
485
+ <div class="row">
486
+
487
+ <div class="col-2">
488
+
489
+ <% if @post.user.image.attached? %>
490
+
491
+ <%= image_tag @post.user.image, class:"avatar m-4"%>
492
+
403
- <% else %>
493
+ <% else %>
404
-
494
+
405
- <%= form_for(current_user.relationships.build) do |f| %>
495
+ <%= image_tag ("defo.jpg"), class:"avatar m-4"%>
496
+
406
-
497
+ <% end %>
498
+
499
+ </div>
500
+
407
- <%= hidden_field_tag :follow_id, user.id %>
501
+ <div class="col-4 align-self-center">
502
+
408
-
503
+ <a href="/users/<%= @post.user.id %>", class="h5", style="text-decoration: none">
504
+
505
+ <p class="h3 text-bold "><%= @post.user.nickname %></p>
506
+
507
+ </a>
508
+
409
- <%= f.submit 'Follow', class: 'btn btn-primary btn-block' %>
509
+ <%= render partial: 'posts/posts', collection: @posts, as: :post %>
510
+
511
+ </div>
512
+
513
+ <%= render 'relationships/follow_button', user: @user %>
514
+
515
+ </div>
516
+
517
+ <%= @post.content %>
518
+
519
+ </div>
520
+
521
+ </div>
522
+
523
+ </div>
524
+
525
+ <hr>
526
+
527
+ <div class="container ">
528
+
529
+ <div class="col text-center text-muted mb-3">
530
+
531
+ <h4>コメント</h4> <%= @comments_count %>
532
+
533
+ </div>
534
+
535
+ <div class="col-8 mx-auto">
536
+
537
+ <% if @comments %>
538
+
539
+ <% @comments.each do |comment| %>
540
+
541
+ <% if user_signed_in? %>
542
+
543
+ <p>
544
+
545
+ <strong><%= link_to comment.user.nickname, "/users/#{comment.user_id}" %>:</strong>
546
+
547
+ <%= comment.text %>
548
+
549
+ </p>
550
+
551
+ <% else %>
552
+
553
+ <p>
554
+
555
+ <strong> <%= comment.user.nickname %>:</strong>
556
+
557
+ <%= comment.text %>
558
+
559
+ </p>
410
560
 
411
561
  <% end %>
412
562
 
413
563
  <% end %>
414
564
 
415
- <% end %>
416
-
417
- ```
418
-
419
- ルーティング
420
-
421
- ```
422
-
423
- Rails.application.routes.draw do
424
-
425
- devise_for :users, only: [:show]
426
-
427
- devise_for :users, controllers: {
428
-
429
- registrations: 'users/registrations'
430
-
431
- }
432
-
433
- root to: "posts#index"
434
-
435
- resources :posts do
436
-
437
- resources :comments, only: [:create, :destroy]
438
-
439
- collection do
440
-
441
- get 'search'
442
-
443
- end
444
-
445
- end
446
-
447
- resources :users, only: [:show, :index, :search]
448
-
449
- resources :relationships, only: [:create, :destroy]
450
-
451
-
452
-
453
- end
454
-
455
- ```
456
-
457
- app/views/posts/show.html.erb
458
-
459
- ```
460
-
461
- <div class="container">
462
-
463
- <div class="row">
464
-
465
- <div class="col-md-8 offset-md-2">
466
-
467
- <%= image_tag @post.image.variant(resize:'800x800').processed %>
468
-
469
- <br>
470
-
471
- <br>
472
-
473
- <br>
474
-
475
- <h1 class="text-center">
476
-
477
- <strong><%= @post.title %></strong>
478
-
479
- </h1>
480
-
481
- <div class="row">
482
-
483
- <div class="col-2">
484
-
485
- <% if @post.user.image.attached? %>
486
-
487
- <%= image_tag @post.user.image, class:"avatar m-4"%>
488
-
489
- <% else %>
490
-
491
- <%= image_tag ("defo.jpg"), class:"avatar m-4"%>
565
+ </div>
566
+
567
+ <div class="row ">
568
+
569
+ <div class="col-8 mx-auto">
570
+
571
+ <% if current_user %>
572
+
573
+ <hr>
574
+
575
+ <%= form_with(model: [@post, @comment], local: true) do |form| %>
576
+
577
+ <div class="form-group mt-3">
578
+
579
+ <%= form.text_area :text, placeholder: "コメント", rows: "2", class: "form-control" %>
580
+
581
+ <div class="text-right">
582
+
583
+ <%= form.submit "SEND", class: "btn btn-outline-secondary "%> <% end %>
584
+
585
+ </div>
586
+
587
+ </div>
588
+
589
+ <% else %>
590
+
591
+ <strong><p class="text-center">※※※ コメントするにはログインしてください ※※※</p></strong>
592
+
593
+ <% end %>
594
+
595
+ </div>
596
+
597
+ </div>
492
598
 
493
599
  <% end %>
494
600
 
495
- </div>
496
-
497
- <div class="col-4 align-self-center">
498
-
499
- <a href="/users/<%= @post.user.id %>", class="h5", style="text-decoration: none">
500
-
501
- <p class="h3 text-bold "><%= @post.user.nickname %></p>
502
-
503
- </a>
504
-
505
- <%= render partial: 'posts/posts', collection: @posts, as: :post %>
506
-
507
601
  </div>
508
602
 
509
- <%= render 'relationships/follow_button', user: @user %>
510
-
511
- </div>
512
-
513
- <%= @post.content %>
514
-
515
- </div>
516
-
517
603
  </div>
518
604
 
519
- </div>
520
-
521
- <hr>
522
-
523
- <div class="container ">
524
-
525
- <div class="col text-center text-muted mb-3">
526
-
527
- <h4>コメント</h4> <%= @comments_count %>
528
-
529
- </div>
530
-
531
- <div class="col-8 mx-auto">
532
-
533
- <% if @comments %>
534
-
535
- <% @comments.each do |comment| %>
536
-
537
- <% if user_signed_in? %>
538
-
539
- <p>
540
-
541
- <strong><%= link_to comment.user.nickname, "/users/#{comment.user_id}" %>:</strong>
542
-
543
- <%= comment.text %>
544
-
545
- </p>
546
-
547
- <% else %>
548
-
549
- <p>
550
-
551
- <strong> <%= comment.user.nickname %>:</strong>
552
-
553
- <%= comment.text %>
554
-
555
- </p>
556
-
557
- <% end %>
558
-
559
- <% end %>
560
-
561
- </div>
562
-
563
- <div class="row ">
564
-
565
- <div class="col-8 mx-auto">
566
-
567
- <% if current_user %>
568
-
569
- <hr>
570
-
571
- <%= form_with(model: [@post, @comment], local: true) do |form| %>
572
-
573
- <div class="form-group mt-3">
574
-
575
- <%= form.text_area :text, placeholder: "コメント", rows: "2", class: "form-control" %>
576
-
577
- <div class="text-right">
578
-
579
- <%= form.submit "SEND", class: "btn btn-outline-secondary "%> <% end %>
580
-
581
- </div>
582
-
583
- </div>
584
-
585
- <% else %>
586
-
587
- <strong><p class="text-center">※※※ コメントするにはログインしてください ※※※</p></strong>
588
-
589
- <% end %>
590
-
591
- </div>
592
-
593
- </div>
594
-
595
- <% end %>
596
-
597
- </div>
598
-
599
- </div>
600
-
601
605
  <div class="container" style="margin-bottom:200px;">
602
606
 
603
607
  ```

2

誤字の修正

2020/10/31 04:22

投稿

kema
kema

スコア6

test CHANGED
File without changes
test CHANGED
@@ -620,7 +620,7 @@
620
620
 
621
621
  ```
622
622
 
623
- その後にhidden_field_tag :follow_id, man.idの部分をf.hidden_field :follow_id, man.id に修正して見ましたがエラー内容は変わりませんでした。
623
+ その後にhidden_field_tag :follow_id, user.idの部分をf.hidden_field :follow_id, user.id に修正して見ましたがエラー内容は変わりませんでした。
624
624
 
625
625
 
626
626
 

1

コントローラーの記述の修正

2020/10/31 00:58

投稿

kema
kema

スコア6

test CHANGED
File without changes
test CHANGED
@@ -264,6 +264,8 @@
264
264
 
265
265
  @comments = @post.comments.includes(:user).order("created_at DESC")
266
266
 
267
+ user = User.find(params[:id])
268
+
267
269
  @user = User.find(params[:id])
268
270
 
269
271
  end