質問編集履歴
1
内容の訂正、コードの訂正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
SyntaxError (コメントを投稿できない)
|
test
CHANGED
@@ -8,37 +8,131 @@
|
|
8
8
|
|
9
9
|
### 発生している問題・エラーメッセージ
|
10
10
|
|
11
|
+
```
|
11
12
|
|
13
|
+
SyntaxError (/Users/xxx/practic/taskleaf/app/controllers/comments_controller.rb:8: syntax error, unexpected ':', expecting `end'
|
12
14
|
|
13
|
-
|
15
|
+
redirect_back = flash: {
|
14
16
|
|
17
|
+
^
|
15
18
|
|
19
|
+
):
|
16
20
|
|
17
|
-
ターミナルにはUnpermitted parameter: :task_idようなメッセージがでているので
|
18
|
-
|
19
|
-
|
21
|
+
```
|
20
|
-
|
21
|
-
|
22
22
|
|
23
23
|
|
24
24
|
|
25
25
|
### 関係がありそうなコード
|
26
26
|
|
27
|
+
```
|
27
28
|
|
29
|
+
class CommentsController < ApplicationController
|
28
30
|
|
31
|
+
def create
|
32
|
+
|
33
|
+
comment = Comment.new(comment_params)
|
34
|
+
|
35
|
+
if comment.save
|
36
|
+
|
37
|
+
flash[:notice] = 'コメントを投稿しました'
|
38
|
+
|
39
|
+
redirect_to comment.task
|
40
|
+
|
41
|
+
else
|
42
|
+
|
43
|
+
redirect_back, flash: {
|
44
|
+
|
45
|
+
comment: comment,
|
46
|
+
|
29
|
-
|
47
|
+
error_messages: comment.errors.full_messages
|
48
|
+
|
49
|
+
}
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
30
54
|
|
31
55
|
|
32
56
|
|
33
|
-
|
57
|
+
def destroy
|
58
|
+
|
59
|
+
end
|
34
60
|
|
35
61
|
|
36
62
|
|
37
|
-
|
63
|
+
private
|
38
64
|
|
39
65
|
|
40
66
|
|
67
|
+
def comment_params
|
68
|
+
|
69
|
+
params.require(:comment).permit(:board_id, :name, :comment)
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
```
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
```
|
80
|
+
|
81
|
+
class TasksController < ApplicationController
|
82
|
+
|
83
|
+
before_action :set_task, only: [:show, :edit, :update, :destroy]
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
def index
|
88
|
+
|
89
|
+
@q = current_user.tasks.ransack(params[:q])
|
90
|
+
|
91
|
+
@tasks = @q.result(distinct: true).page(params[:page])
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
def show
|
98
|
+
|
99
|
+
@comment = @task.comments.new
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
```
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
```
|
108
|
+
|
109
|
+
.p-comment__formBox
|
110
|
+
|
111
|
+
.p-comment__formTitle コメント記入
|
112
|
+
|
113
|
+
= form_for comment do |f|
|
114
|
+
|
115
|
+
= f.hidden_field :task_id
|
116
|
+
|
117
|
+
.form-group
|
118
|
+
|
119
|
+
= f.label :name, '名前'
|
120
|
+
|
41
|
-
|
121
|
+
= f.text_field :name, class: 'form-control'
|
122
|
+
|
123
|
+
.form-group
|
124
|
+
|
125
|
+
= f.label :comment, 'コメント'
|
126
|
+
|
127
|
+
= f.text_area :comment, class: 'form-control', rows: 4
|
128
|
+
|
129
|
+
= f.submit '送信', class: 'btn btn-primary'
|
130
|
+
|
131
|
+
```
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
|
42
136
|
|
43
137
|
|
44
138
|
|