Select photo nested form Rails -


i have class house, has_many house_photos. had created bulk of photos (@mainentrance), users can select house.photo, using radio button. this, have nested form form_tag. tried followed post (using form_for each loop), it's not working because have nested form.

here code:

<%= form_tag new_house_path |f| %>  <div class="col-md-3 detailsnew">    <div class="field">     <%= text_field :title, :autofocus => true, class: 'form-control' %>   </div>  </div>  <div class="col-md-12">    <h3> main entrance </h3>    <%= fields_for :house_photos, @houses.house_photos |house_photo| %> <!-- nested  form-->      <%= house_photo.hidden_field :title, :value => "main entrance" %><br /> <!-- title house_photo -->      <% @mainentrance.each |photo| %> <!-- render image users can select -->         <a class="fancybox-thumb" rel="fancybox-thumb" href="<%= photo.attachment %>"><img src="<%=  photo.attachment %>" alt="" style ="margin: auto; display: inline-block; padding: 5px 0px; height: 200px; width: 300px;"/></a>         <%= fields_for "house_photo[#{photo.id}]", photo |p| %>           <%= house_photo.radio_button 'attachment', class: 'form-control', :value => p.attachement %> <!-- radio_button each photo -->         <% end %>      <% end %>  <div class="col-md-12 actions" >   <%= f.submit "submit house", :class => "btn btn-small btn-primary", :style => "color:#ffffff" %> </div> <% end %> 

basically, trying use value attachment of @mainentrance house_photo. using code error undifined method 'attachment' #<activerecord::associations::collectionproxy::activerecord_associations...>

i fixed problem using form_for. post useful rails form multiple nested models causes issues radio groups

here code:

  <%= form_for(@houses) |f| %>       <div class="col-md-3 detailsnew">        <div class="field">         <%= f.label :title %><br>         <%= f.text_field :title, :autofocus => true, class: 'form-control' %>       </div>      </div>      <div class="col-md-12">        <h3> main entrance </h3>        <%= fields_for :house_photos, @houses.house_photos |house_photo| %> <!-- nested  form-->          <%= house_photo.hidden_field :title, :value => "main entrance" %><br /> <!-- title house_photo -->          <% @mainentrance.each |photo| %> <!-- render image users can select -->             <a class="fancybox-thumb" rel="fancybox-thumb" href="<%= photo.attachment %>"><img src="<%=  photo.attachment %>" alt="" style ="margin: auto; display: inline-block; padding: 5px 0px; height: 200px; width: 300px;"/></a>             <!-- solution -->               <%= house_photo.radio_button(:imageurl, photo.attachment) %>          <% end %>      <div class="col-md-12 actions" >       <%= f.submit "submit house", :class => "btn btn-small btn-primary", :style => "color:#ffffff" %>     </div>     <% end %>  </div> 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -