質問編集履歴
2
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -24,6 +24,62 @@
|
|
24
24
|
|
25
25
|
```ruby
|
26
26
|
|
27
|
+
投稿一覧表示画面
|
28
|
+
|
29
|
+
app/views/posts/index.html.erb
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
<%# 投稿表示 %>
|
34
|
+
|
35
|
+
<div class="post-content">
|
36
|
+
|
37
|
+
<h2 class="title">Post List</h2>
|
38
|
+
|
39
|
+
<ul class="post-lists">
|
40
|
+
|
41
|
+
<% @posts.each do |post|%>
|
42
|
+
|
43
|
+
<li class="list">
|
44
|
+
|
45
|
+
<%# 詳細画面へ遷移 %>
|
46
|
+
|
47
|
+
<%= link_to post_path(post.id), method: :get do %>
|
48
|
+
|
49
|
+
<div class="post-image-content">
|
50
|
+
|
51
|
+
<%= image_tag post.image, class: "post-image" if post.image.attached?%>
|
52
|
+
|
53
|
+
</div>
|
54
|
+
|
55
|
+
<% end %>
|
56
|
+
|
57
|
+
<div class="post-info">
|
58
|
+
|
59
|
+
<h3 class="post-title">
|
60
|
+
|
61
|
+
<%= post.title%>
|
62
|
+
|
63
|
+
</h3>
|
64
|
+
|
65
|
+
</div>
|
66
|
+
|
67
|
+
</li>
|
68
|
+
|
69
|
+
<% end %>
|
70
|
+
|
71
|
+
</ul>
|
72
|
+
|
73
|
+
</div>
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
```
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
|
27
83
|
投稿詳細画面
|
28
84
|
|
29
85
|
app/views/posts/show.html.erb
|
1
ファイル情報追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -26,6 +26,8 @@
|
|
26
26
|
|
27
27
|
投稿詳細画面
|
28
28
|
|
29
|
+
app/views/posts/show.html.erb
|
30
|
+
|
29
31
|
|
30
32
|
|
31
33
|
<%= render "shared/second_header"%>
|
@@ -116,7 +118,11 @@
|
|
116
118
|
|
117
119
|
```ruby
|
118
120
|
|
119
|
-
コントローラー
|
121
|
+
投稿用コントローラー
|
122
|
+
|
123
|
+
posts_controller.rb
|
124
|
+
|
125
|
+
|
120
126
|
|
121
127
|
|
122
128
|
|
@@ -222,6 +228,52 @@
|
|
222
228
|
|
223
229
|
```ruby
|
224
230
|
|
231
|
+
コメント用コントローラー
|
232
|
+
|
233
|
+
comments_controller.rb
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
class CommentsController < ApplicationController
|
238
|
+
|
239
|
+
def create
|
240
|
+
|
241
|
+
comment = Comment.create(comment_params)
|
242
|
+
|
243
|
+
redirect_to "/posts/#{comment.post.id}"
|
244
|
+
|
245
|
+
end
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
def destroy
|
250
|
+
|
251
|
+
end
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
private
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
def comment_params
|
260
|
+
|
261
|
+
params.require(:comment).permit(:comment).merge(user_id: current_user.id, post_id: params[:post_id])
|
262
|
+
|
263
|
+
end
|
264
|
+
|
265
|
+
end
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
```
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
```ruby
|
276
|
+
|
225
277
|
投稿用モデル
|
226
278
|
|
227
279
|
|
@@ -242,9 +294,11 @@
|
|
242
294
|
|
243
295
|
|
244
296
|
|
245
|
-
|
246
|
-
|
247
|
-
```
|
297
|
+
```
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
|
248
302
|
|
249
303
|
|
250
304
|
|
@@ -278,12 +332,16 @@
|
|
278
332
|
|
279
333
|
|
280
334
|
|
335
|
+
|
336
|
+
|
281
337
|
```ruby
|
282
338
|
|
283
339
|
|
284
340
|
|
285
341
|
削除用リンク
|
286
342
|
|
343
|
+
app/views/shared/_second_header.html.erb
|
344
|
+
|
287
345
|
|
288
346
|
|
289
347
|
<% if user_signed_in? && @post.user_id == current_user.id %>
|