嵌套循环出错
我正在尝试制作包含预定义问题的报告。 我已经从脚手架上提出了问题并填补了它。 现在是为每个问题分配答案字段。
[DATA TYPE]
class Report < ActiveRecord::Base
has_many :ansbwer_singles
end
class AnswerSingle < ActiveRecord::Base
belongs_to :report
end
reports/_form.html.erb
<div class="question">
<% QuestionSingle.all.each_with_index do |question, index| %>
<p><%= index+1 %>. <%= question.content %></p>
<p>
<%= f.fields_for :answer_singles do |answer| %>
<%= answer.text_area :content %>
<% end %>
</p>
<% end %>
它显示得很好,但一旦提交就会出错,
1. Question 1
[text area]
2. Question 2
[text area]
[error when submit]
AnswerSingle(#18194030) expected, got Array(#1133380)
我认为原因是使用 :answer_singles
作为字段。 有没有更好的代码来实现这个?
I'm trying to make a report with predefined questions.
I have made questions from the scaffold and filled it.
Now is to assign answer fields per each questions.
[DATA TYPE]
class Report < ActiveRecord::Base
has_many :ansbwer_singles
end
class AnswerSingle < ActiveRecord::Base
belongs_to :report
end
reports/_form.html.erb
<div class="question">
<% QuestionSingle.all.each_with_index do |question, index| %>
<p><%= index+1 %>. <%= question.content %></p>
<p>
<%= f.fields_for :answer_singles do |answer| %>
<%= answer.text_area :content %>
<% end %>
</p>
<% end %>
it shows well but once submit it makes error
1. Question 1
[text area]
2. Question 2
[text area]
[error when submit]
AnswerSingle(#18194030) expected, got Array(#1133380)
I think the reason is using :answer_singles
for fields for.
Is there any better code to implement this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论