質問編集履歴

1

コードの追加と修正

2020/10/26 11:20

投稿

yozakura10
yozakura10

スコア8

test CHANGED
File without changes
test CHANGED
@@ -68,6 +68,52 @@
68
68
 
69
69
  **関係ありそうなコードを載せます**
70
70
 
71
+ config/routes.rb
72
+
73
+ ```ruby
74
+
75
+ Rails.application.routes.draw do
76
+
77
+ devise_for :users
78
+
79
+ root to: "prototypes#index"
80
+
81
+ resources :users, only: [:new, :edit, :update, :show]
82
+
83
+ resources :prototypes, only: [:index, :new, :create, :show, :edit, :update, :destroy,] do
84
+
85
+ resources :comments, only: [:create]
86
+
87
+ end
88
+
89
+
90
+
91
+ devise_scope :user do
92
+
93
+ get '/users/sign_out' => 'devise/sessions#destroy'
94
+
95
+ end
96
+
97
+
98
+
99
+ end
100
+
101
+
102
+
103
+
104
+
105
+
106
+
107
+ ```
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+
71
117
  app/controllers/prototypes_controller.rb
72
118
 
73
119
  ```ruby
@@ -300,20 +346,24 @@
300
346
 
301
347
 
302
348
 
303
- <%= link_to "by" + @prototype.user.name , prototype_path(@prototype.id), class: :prototype__user %>
349
+ <%= link_to "by #{@prototype.user.name}さん" , user_path(@prototype.user), class: :prototype__user %>
304
350
 
305
351
  <%# 上の記述で@prototypeにuserモデルからnameカラムを持ってくるコードができた %>
306
352
 
307
353
  <%# プロトタイプの投稿者とログインしているユーザーが同じであれば以下を表示する %>
308
354
 
355
+ <% if current_user == @prototype.user%>
356
+
309
357
  <div class="prototype__manage">
310
358
 
311
- <%= link_to "編集する", edit_prototype_path, class: :prototype__btn %>
359
+ <%= link_to "編集する", edit_prototype_path(@prototype), class: :prototype__btn %>
312
-
360
+
313
- <%= link_to "削除する", prototype_path, method: :delete, class: :prototype__btn %>
361
+ <%= link_to "削除する", prototype_path(@prototype), method: :delete, class: :prototype__btn %>
314
362
 
315
363
  </div>
316
364
 
365
+ <% end %>
366
+
317
367
  <%# // プロトタイプの投稿者とログインしているユーザーが同じであれば上記を表示する %>
318
368
 
319
369
  <div class="prototype__image">
@@ -376,10 +426,6 @@
376
426
 
377
427
  <% end %>  
378
428
 
379
- <% else %>
380
-
381
- <strong><p>※※※ コメントの投稿には新規登録/ログインが必要です ※※※</p></strong>
382
-
383
429
  <% end %>
384
430
 
385
431
  <%# // ログインしているユーザーには上記を表示する %>
@@ -414,8 +460,6 @@
414
460
 
415
461
  </main>
416
462
 
417
-
418
-
419
463
  ```
420
464
 
421
465