0
我的应用程序有问题,其中有许多答案,其中有许多评论。param丢失或值为空:在Rails 4中存储具有关系的实体
不过,我试图挽救一个答案的评论时遇到问题,我收到此错误:
param is missing or the value is empty: comment
突出显示的行,这是一个:
params.require(:comment).permit(:description)
的图,其中评论创建的是问题的展示视图,所以在QuestionController
首先我加载comment
:
def show
@answer = Answer.new
@comment = Comment.new
end
这是该视图的样子:
<p>
<strong>Answers:</strong>
</p>
<% unless @question.answers.empty? %>
<ul class="list-groups">
<% @question.answers.each do |answer| %>
<li class="list-group-item">
<h4><%= answer.description %></h4>
<hr>
<%= form_for(@comment, html: { class: "form-inline" }) do |f| %>
<div class="form-group">
<%= text_field_tag 'description', nil, placeholder: 'Comment this answer', class: "form-control" %>
</div>
<div class="form-group">
<%= f.submit "Comment", class: "btn btn-default" %>
</div>
<input id="answer_id" name="answer[id]" type="hidden" value="<%= answer.id %>">
<% end %>
</li>
<% end %>
</ul>
<% else %>
有什么不对?