开发者

looping through images and displaying associated image details

开发者 https://www.devze.com 2023-02-24 05:44 出处:网络
I have an edit page (for a car model) which loops through a list of images and display the description associated with each image in a text field where user can edit it.

I have an edit page (for a car model) which loops through a list of images and display the description associated with each image in a text field where user can edit it.

My problem is that for each image, instead of displaying its associated description, all the descriptions associated with the car (and not that parti开发者_如何学Ccular image) are displayed for each particular image. For e.g, if i have am editing a car details and this car has 3 images, each having a description. All 3 descriptions are displayed for each image, resulting in 9 descriptions field in all on my edit page.

<% @car.images.each do | image | %>
<div class="car_photos">
  <%= image_tag(image.data.url(:thumb), :alt => '') %>
     <% f.fields_for :images do |builder| %>
       <%= render "imageEdit", :f => builder %>
     <% end %>
</div>
<% end unless @car.images.first.new_record? rescue nil %> 

_imageEdit.html.erb:

<% f.fields_for :descriptions do |builder| %>
<p>Description:<%= builder.text_area :desc %></p>
<% end %> 

Any suggesion on how to solve this prob? Thanks


Either do

<% f.fields_for :images, image do |builder| %>

or

<% f.fields_for image do |builder| %>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号