Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6793539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:06:45+00:00 2026-05-26T18:06:45+00:00

the problem is that I have a form that normally should render photos of

  • 0

the problem is that I have a form that normally should render photos of current car and it does so but it renders them multiple times.. like this: I have 5 photos for car_id 2 and on screen I have 5 times these photos displayed.

12345
12345
12345
12345
12445

If I add a photo, then it will be diplayed 6 times. what is the problem and how can I solve it, I’ve tried a lot of: replace this, replace that but nothing.

Here is a piece of the form itself

<%= form_for @car, :html => { :method => :put }, :html => { :multipart => true } do |f| %>
...
...
    <% for photo in @car.uploads %>
    <div style="width:750px !important;">
          <%= f.fields_for :uploads do |photo_fields| %>
            <%unless photo_fields.object.new_record? %>
                <div style="width:150px;float:left;">
                  <%= image_tag(photo_fields.object.photo.url(:thumb)) %>
                  <p><%= photo_fields.check_box :_destroy %>  Delete item</p>
                </div>
            <% end %>
          <% end %>
      </div>  
....
...
<% end %>

and the console:

Started GET "/cars/2/edit" for 127.0.0.1 at Sun Nov 06 22:50:17 +0200 2011
  Processing by CarsController#edit as HTML
  Parameters: {"id"=>"2"}
  User Load (0.2ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
  SQL (4.1ms)  SHOW TABLES
  Car Load (0.2ms)  SELECT `cars`.* FROM `cars` WHERE `cars`.`id` = 2 LIMIT 1
  CACHE (0.0ms)  SELECT `cars`.* FROM `cars` WHERE `cars`.`id` = 2 LIMIT 1
  Carname Load (0.2ms)  SELECT `carnames`.* FROM `carnames`
  Carmodel Load (0.2ms)  SELECT `carmodels`.* FROM `carmodels`
Rendered shared/_error_messages.html.erb (1.0ms)
  Upload Load (0.2ms)  SELECT `uploads`.* FROM `uploads` WHERE (`uploads`.car_id = 2)
  Carname Load (0.2ms)  SELECT `carnames`.* FROM `carnames` WHERE `carnames`.`id` = 1 LIMIT 1
  Carmodel Load (0.2ms)  SELECT `carmodels`.* FROM `carmodels` WHERE `carmodels`.`id` = 5 LIMIT 1
Rendered uploads/_upload.html.erb (8.1ms)
Rendered cars/_show.html.erb (2.7ms)
WARNING: Can't mass-assign protected attributes: user_id
Rendered cars/_form.html.erb (460.6ms)
Rendered welcome/_sliderempty.html.erb (1.0ms)
Rendered welcome/_footer.html.erb (0.5ms)

Thanks for your time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:06:46+00:00Added an answer on May 26, 2026 at 6:06 pm

    just remove the for loop, fields_for already iterates over the photos so you iterate twice you get the photos twice.

    In response to your comment: try to pass the collection explicitly like:

    <%= f.fields_for :uploads, @car.uploads do |photo_fields| %>

    So here you go:

    <%= form_for @car, :html => { :method => :put }, :html => { :multipart => true } do |f| %>
    ...
    ...
        <div style="width:750px !important;">
              <%= f.fields_for :uploads, @car.uploads do |photo_fields| %>
                <%unless photo_fields.object.new_record? %>
                    <div style="width:150px;float:left;">
                      <%= image_tag(photo_fields.object.photo.url(:thumb)) %>
                      <p><%= photo_fields.check_box :_destroy %>  Delete item</p>
                    </div>
                <% end %>
              <% end %>
          </div>  
    ....
    ...
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have bought a template that have built in contact form problem is that
I have an InfoPath form with several fields on, the problem is that one
I have a HTML form where I use several buttons. The problem is that
I have a following problem, I have HTML form that uploads a file with
Fact: I'm not that good with jQuery. Problem: I have a form containing dynamically
The problem I am encountering is that for my login form I have to
I have a dropdown in my form that has a problem to populate when
I have a problem. The client is claiming that a prize signup form I
I have multiple hidden form fields which store values about the the current view
I want to access certain form elements from classes that normally don't have access

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.