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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:13:29+00:00 2026-05-25T20:13:29+00:00

When you edit a model with a form that contains nested model attributes, it

  • 0

When you edit a model with a form that contains nested model attributes, it seems as if the child objects are only validated if at least one field on the child object has changed.

However, suppose that your validation rules have changed, such that one or more of the nested models being edited are no longer considered valid. How can you force Rails to re-validate the all fields for all of the nested models?

UPDATE

Here’s a total hack that works. I hope somebody knows a more elegant approach.

# parent.rb

has_many :children

# Manually force validation of all the children.
# This is lame because if you have multiple child associations, you'll have to 
# keep updating this method.
def reset_validation
   self.children.each{|child| child.valid? }
   self.valid?
end

# parent_controller.rb
def update
  @parent.reset_validation

  if @parent.update_attributes(params[:parent])
    redirect_to(root_path, :notice => 'Parent successfully updated.')
  else
   render :action => "edit"
  end
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-25T20:13:30+00:00Added an answer on May 25, 2026 at 8:13 pm

    The answer to this turned out to be rather simple. On the parent model, you simply explicitly declare that you want the associated children validated.

    # parent.rb
    validates_associated :children
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a strongly-typed edit form for a MVC model that contains a
Edit: I am trying to bind a single view model object that contains a
I have a model that contains an IEnumerable of a list of custom objects.
I have a complex form for a model Schedule that belongs to a parent
I have an edit form that uses an ajax form to submit to the
I'm trying to create an element that contains a form so it can be
I have a page that contains a form, where part of it is dynamically
when creating a fairly complicated form that will be used to edit a database
I have a Model class for a Generic Object that contains an array of
I have an Entity (QuoteSheet) that contains a child entity (QuoteTask), which is loaded

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.