質問編集履歴
2
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -5,15 +5,6 @@
|
|
5
5
|
エラー内容のとおりcommentsフォルダにindex.html.erbを作成しましたが、
|
6
6
|
真っ白なページに遷移され非同期通信になりません。
|
7
7
|
|
8
|
-
また気になる点があります。
|
9
|
-
以下の画像のようにところどころ文字に色がない箇所がありますが
|
10
|
-
これは反映されていないと言うことでしょうか?
|
11
|
-
**comments/index.js.erb**
|
12
|
-

|
13
|
-
|
14
|
-
**view/posts/show.html.erb**
|
15
|
-

|
16
|
-
|
17
8
|
##comments_controller.rb
|
18
9
|
```ここに言語を入力
|
19
10
|
class CommentsController < ApplicationController
|
1
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -38,4 +38,32 @@
|
|
38
38
|
params.require(:comment).permit(:comment_content, :post_id, :user_id )
|
39
39
|
end
|
40
40
|
end
|
41
|
+
```
|
42
|
+
##comments/_form.html.erb
|
43
|
+
```ここに言語を入力
|
44
|
+
<%= form_with(model: [post, comment] ) do |form| %>
|
45
|
+
<div>
|
46
|
+
<%= form.text_area :comment_content %>
|
47
|
+
</div>
|
48
|
+
<div class="actions">
|
49
|
+
<%= form.submit "コメントをする" %>
|
50
|
+
</div>
|
51
|
+
<% end %>
|
52
|
+
```
|
53
|
+
##comments/_index.html.erb
|
54
|
+
```ここに言語を入力
|
55
|
+
<% comments.each do |comment| %>
|
56
|
+
<% unless comment.id.nil? %>
|
57
|
+
<p><%= link_to "#{comment.user.name}さん" %></p>
|
58
|
+
<p>コメント:<%= comment.comment_content %></p>
|
59
|
+
<% if comment.user == current_user %>
|
60
|
+
<p><%= link_to 'コメントを削除する', post_comment_path(comment.post_id, comment.id), method: :delete, remote: true %></p>
|
61
|
+
<% end %>
|
62
|
+
<% end %>
|
63
|
+
<% end %>
|
64
|
+
```
|
65
|
+
##comments/index.js.erb
|
66
|
+
```ここに言語を入力
|
67
|
+
$("#comments_area").html("<%= j(render 'index', { comments: @comment.post.comments }) %>")
|
68
|
+
$("textarea").val('')
|
41
69
|
```
|