Ruby on Rails 2 - Complex forms for Lesson, Questions & Answers -
i have 4 models - users, lessons, questions & answers. each user can create lesson questions , ask other users answer questions , submit form. ran problem creating view display lesson list of questions , blank answer field underneath each question. have working code (shown here) loops through questions , shows text field each question , answer. trying change questions shown headers , answers shown editable fields. hope makes sense. noob ror. couldn't find answer online. thank much.
--view
<% form_for @lesson |f| %> <%= f.error_messages %> <% f.fields_for :questions |builder| %> <%= render "question_fields", :f => builder %> <% end %> <p><%= f.submit "submit answers"%> <% end %>
--partial _question_fields.html.erb
<%= f.text_area :prompt, :rows => 1 %> <br /> <% f.fields_for :answers |builder| %> <%= render "answer_fields", :ff => builder %> <% end %><br />
--partial _answer_fields.html.erb
<%= ff.text_area :data, :rows => 3 %>
you should able access "question object" so:
<%= f.object.prompt %>
which should output "prompt" field of question object passed fields_for. i'm not sure if can combine <%= f.label %>
or not.
best of luck!
~robbie
Comments
Post a Comment