Prepopulate complex form values in rails edit view -


i have assessment form renders list of questions, , accepts answers each question. form data submitted manually via ajax.

i'm having issue when trying pre-populate data in edit view. here's how views look:

edit.html.erb:

<div class="container">     <%= render 'assessment_form', :locals=> {:assessment => @assessment} %> </div> 

_assessment_form.html.erb:

<%= form_for @assessment |f| %>    <%= f.submit 'save', :class=> "btn btn-primary", :style=>"width: 100%;" %>        <div class="col-sm-2 col-sm-offset-10">         <h4>show on followup?</h4>      </div>        <% @assessment.questions.where(category:"s").each |question| %>         <%= render 'question_fields', :question=> question, :f=> f %>       <% end %>      <%= f.hidden_field :patient_id, :value=> @assessment.patient.id %>     <%= f.hidden_field :template_id, :value=> @assessment.template_id %> <% end %> 

_question_fields.html.erb:

<p><%= question.content %></p>    <%= f.fields_for :answer |builder| %>      <div class="row question">        <div class="col-sm-2 pull-right toggle">         <%= builder.check_box :tracking, {:checked=> false, :class=>"trackable", :data => {:'on-text' => "yes", :'off-text' => "no", :'on-color'=> "success", :question => question.id}}, 0 , 1 %>       </div>        <div class="col-sm-10">           <%= builder.text_area :content, :class=>"form-control question-field", :data => {:question => question.id} %>        </div>      </div>    <% end %> 

but none of answers content rendering in view, form fields blank.

here's example call: assessment.last.answers.first.content give me string "test". should showing in text_area box it's not.

just do, instance variable @assessment passed partial.

<%= render 'assessment_form' %> 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -