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

  • Home
  • SEARCH
  • 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 1073735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:01:45+00:00 2026-05-16T21:01:45+00:00

I have a nested form problem. I implemented the nested forms solution form the

  • 0

I have a nested form problem. I implemented the nested forms solution form the railscasts 196 & 197. It works if I have no validation errors.

So, form renders perfectly when it is loaded, including the nested fields (in the fields_for part).

But, the form has validations. When a validation fails, the controller does render :new. Then the form renders the linked model fields ok, but the nested fields are not anymore rendered. Is there a solution for this?

the controller

  def new
    @property = Property.new
    @property.images.build
  end

  def create
    @property = Property.new(params[:property])
    if @property.save
      flash[:success] = t('Your_property') + ' ' + t('is_successfully_created')
      redirect_to myimmonatie_url
    else
      render :action => 'new'
    end
  end

part of the view:

<% form_for :property, @property, :url => { :action => "create" }, :html => { :multipart => true } do |f| %>
  <div id="new-property-form-spannedcols">
      <div class="formField inptRequired">
        <%= f.label :postal_code, t("Postal_code") %>
        <%= f.text_field :postal_code, :class => 'inptMedium short' %>
      </div>
      <div id="city_row" class="formField inptRequired">
        <%= f.label :city, t("City") %>
        <div id="city_cell">
          <%= render :partial => 'ajax/cities', :locals => { :postal_code => @property.postal_code } %>
        </div>
      </div>

      ...

      <% f.fields_for :images do |builder| %>
        <div class="formField">
          <%= builder.label :photo, t("Photo_path_max_3mb") %>
          <%= builder.file_field :photo, :class => 'inptMedium' %>
          <%= builder.hidden_field :order, :value => "1" %>
        </div>
      <% end %>
  </div> <!-- /new-property-form-spannedcols -->
  <div class="formBtn">
    <%= f.submit t("Save"), :class => 'btnMedium bg-img-home' %>&nbsp;
  </div> <!-- /formBtn -->
<%- end -%>
  • 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-16T21:01:46+00:00Added an answer on May 16, 2026 at 9:01 pm

    Does it throw an error?

    My guess is your problem is that in your new action, you are doing @property.images.build, which is not in your edit action. When the validation fails, it will render your new action, but won’t run your new action. You could try putting @property.images.build in the else clause of your create action like:

    else
      @property.images.build
      render :action => 'new'
    end
    

    Not the cleanest way to do it, by any means, but this will help track down if that is your issue.

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

Sidebar

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.