質問編集履歴
1
コードの記入など
test
CHANGED
File without changes
|
test
CHANGED
@@ -3,3 +3,163 @@
|
|
3
3
|
ページの検証をするとどのform_withにはデフォルトにあるremote :trueが機能していませんでした
|
4
4
|
|
5
5
|
何が原因でしょうか?
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
Instagram風アプリを作っていまして、
|
10
|
+
|
11
|
+
<div id="comment-post-<%= post.id.to_s %>">
|
12
|
+
|
13
|
+
<%= render 'comment_list', { post: post } %>
|
14
|
+
|
15
|
+
</div>
|
16
|
+
|
17
|
+
<%= link_to time_ago_in_words(post.created_at).upcase + "前", post_path(post),
|
18
|
+
|
19
|
+
class: "light-color post-time no-text-decoration" %>
|
20
|
+
|
21
|
+
<hr>
|
22
|
+
|
23
|
+
<div class="row actions" id="comment-form-post-<%= post.id.to_s %>">
|
24
|
+
|
25
|
+
<%= form_with model: [post, Comment.new], class: "w-100" do |f| %>
|
26
|
+
|
27
|
+
<%= f.hidden_field :user_id, value: current_user.id %>
|
28
|
+
|
29
|
+
<%= f.hidden_field :post_id, value: post.id %>
|
30
|
+
|
31
|
+
<%= f.text_field :comment, class: "form-control comment-input border-0", placeholder: "コメント ...", autocomplete: :off %>
|
32
|
+
|
33
|
+
<% end %>
|
34
|
+
|
35
|
+
</div>
|
36
|
+
|
37
|
+
</div>
|
38
|
+
|
39
|
+
</div>
|
40
|
+
|
41
|
+
</div>
|
42
|
+
|
43
|
+
</div>
|
44
|
+
|
45
|
+
</div>
|
46
|
+
|
47
|
+
<% end %>
|
48
|
+
|
49
|
+
ここでコメントを作り送信すると、
|
50
|
+
|
51
|
+
ActionController::UnknownFormat in CommentsController#create
|
52
|
+
|
53
|
+
ActionController::UnknownFormat
|
54
|
+
|
55
|
+
Extracted source (around line #7):
|
56
|
+
|
57
|
+
5
|
58
|
+
|
59
|
+
6
|
60
|
+
|
61
|
+
7
|
62
|
+
|
63
|
+
8
|
64
|
+
|
65
|
+
9
|
66
|
+
|
67
|
+
10
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
@post = @comment.post
|
72
|
+
|
73
|
+
if @comment.save
|
74
|
+
|
75
|
+
respond_to :js
|
76
|
+
|
77
|
+
else
|
78
|
+
|
79
|
+
flash[:alert] = "コメントに失敗しました"
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
Rails.root: /myapp
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
Application Trace | Framework Trace | Full Trace
|
90
|
+
|
91
|
+
app/controllers/comments_controller.rb:7:in `create'
|
92
|
+
|
93
|
+
Request
|
94
|
+
|
95
|
+
Parameters:
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
{"authenticity_token"=>"[FILTERED]", "comment"=>{"user_id"=>"1", "post_id"=>"6", "comment"=>"こんにちは"}, "post_id"=>"6"}
|
100
|
+
|
101
|
+
Toggle session dump
|
102
|
+
|
103
|
+
Toggle env dump
|
104
|
+
|
105
|
+
Response
|
106
|
+
|
107
|
+
Headers:
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
None
|
112
|
+
|
113
|
+
このようなエラーがおこりました。
|
114
|
+
|
115
|
+
コントローラーはこのようになります
|
116
|
+
|
117
|
+
class CommentsController < ApplicationController
|
118
|
+
|
119
|
+
before_action :authenticate_user!
|
120
|
+
|
121
|
+
def create
|
122
|
+
|
123
|
+
@comment = Comment.new(comment_params)
|
124
|
+
|
125
|
+
@post = @comment.post
|
126
|
+
|
127
|
+
if @comment.save
|
128
|
+
|
129
|
+
respond_to :js
|
130
|
+
|
131
|
+
else
|
132
|
+
|
133
|
+
flash[:alert] = "コメントに失敗しました"
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
def destroy
|
142
|
+
|
143
|
+
@comment = Comment.find_by(id: params[:id])
|
144
|
+
|
145
|
+
@post = @comment.post
|
146
|
+
|
147
|
+
if @comment.destroy
|
148
|
+
|
149
|
+
respond_to :js
|
150
|
+
|
151
|
+
else
|
152
|
+
|
153
|
+
flash[:alert] = "コメントの削除に失敗しました"
|
154
|
+
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
private
|
162
|
+
|
163
|
+
def comment_params
|
164
|
+
|
165
|
+
params.required(:comment).permit(:user_id, :post_id, :comment)
|