nesting forms without using partials
I would like to know if the code below is good.
% form_for @survey do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :name 开发者_如何学编程%><br />
<%= f.text_field :name %>
</p>
<% f.fields_for :questions do |builder| %>
<%= builder.text_field :question %>
<% builder.fields_for :answers do |answer|
<p>Answer: <%= answer.text_field :answer %>
<% end %>
<% end %>
<p><%= f.submit "Submit" %></p>
<% end %>
Is this piece if code <%= builder.text_field :question %>
good?
Am asking this because when i render my form, nothing is displayed for answer and when i view page source, i don't have anything for the answer section.
Many many thanks for your help. :)
Replace:
<% form_for @survey do |f| %>
with:
<%= form_for @survey do |f| %>
and the same here:
<% f.fields_for :questions do |builder| %>
to be replaced by:
<%= f.fields_for :questions do |builder| %>
I guess you've understood you have to proceed again with answers
:)
精彩评论