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 6650979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:57:22+00:00 2026-05-26T00:57:22+00:00

I am using the nested_form gem but ran in to one use case that

  • 0

I am using the nested_form gem but ran in to one use case that is giving me some trouble. I have one particular nested form where the partial for existing nested objects is different from the one needed when adding a new object. (The particular use case is images – existing uploaded images display an image tag, new image objects need to render a file_field for upload.)

One thing I tried is to check within the partial for f.object.nil? to determine what to render but both new and existing objects still yielded the existing object partial code. I’m assuming this has something to do with the way the nested_form BuilderMixin is calling fields_for?

Is there an easy way to do this that I am missing? Or do I need to look at modifying the nested_form link_to_add code to accommodate this?

For reference, here was my attempt at using one partial:

<tr>
    <% if !f.object.nil? %>
        <td>
            <a href="/customer_images/<%= f.object.id %>" target="_new">
                <%= image_tag f.object.picture.url -%>
            </a>
        </td>
        <td>
            Description: <%= f.object.image_description %><br/>
            Date Uploaded: <%= (f.object.nil? || f.object.created_at.nil?) ? "Not yet uploaded." : f.object.created_at.strftime("%A %h %d, %Y %I:%M %p") %>
            <br>
            <%= f.link_to_remove "Remove this image" %>
        </td>
    <% else %>
        <td>&nbsp;</td>
        <td>
            <%= label :image, :file, "Select File:" %><%= f.file_field :picture %><br />
            Description: <%= f.text_field :image_description %><br />
        </td>   
    <% end %>
</tr>
  • 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-26T00:57:23+00:00Added an answer on May 26, 2026 at 12:57 am

    No object could be nil there. You should check whether or not the object exists in database calling the new_record? method.

    See doc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using some nested layouts in Ruby on Rails, and in one of
I want to scrape some html pages that have nested form elements with lxml.
I'm using the gem nested_form in a Rails 3.1 application. The problem is that
I have a nested form in a Rails 3.1 app, using Cocoon gem. In
I have a one to many relationship with a child form that is nested
I have a nested form in a rails view that is called like this
I have a page that uses Ryan Bates nested_form plugin . The plugin is
I'm having trouble with and RSpec view test. I'm using nested resources and the
I have a nested form for has_many relationship using accepts_nested_attributes_for method. If I don't
I'm using ryan bates' plugin nested_form and i have been trying to write my

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.