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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:47:58+00:00 2026-05-31T00:47:58+00:00

So I am seeing some very strange functionality in my app. I have a

  • 0

So I am seeing some very strange functionality in my app. I have a pretty complex form with nested attributes. Basically on a failed validation I am returned to the form and the failed record has been duplicated. It seems it may be something having the way a model initializes a record after it has failed validation.

NOTE: I am using formtastic to build the form but I have ruled it out as the culprit.

My model is pretty complex, but the parts that matter are:

...
accepts_nested_attributes_for :users
...
after_initialize :build_structure
...
private

def build_structure
   # builds the first user when the firm is initialized
   if users.length < 1
       logger.debug "First User!!!"
       user = users.new
       contact = user.contact = Contact.new
       contact.email_addresses.new
   end
end

A Basic Controller:

def new
  @firm = Firm.new
  render "new", layout: "blankslate" # new.html.erb
end

def create
    @firm = Firm.new(params[:firm])

    respond_to do |format|
        if @firm.save
            format.html { redirect_to root_url(subdomain: @firm.url)}
        else
            format.html { render action: "new", layout: "blankslate" }
        end
    end
end

And the view:

.container
  .row
    .span4.offset4.well
      .page-header
        %h1 Create Your Firm
      = semantic_form_for @firm, url: signup_path do |f|
        = f.input :name
        = f.input :url
        .page-header
          %h1 Create Your User
        = f.fields_for :users do |u|
          = u.fields_for :contact do |c|
            = c.input :first_name
            = c.input :last_name
            = c.fields_for :email_addresses do |cf|
              = cf.input :value, label: "Email Address"
          = u.input :password
          = u.input :password_confirmation


        = f.submit "Signup", class: "btn btn-primary"
  • 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-31T00:47:59+00:00Added an answer on May 31, 2026 at 12:47 am

    The reason that this is happening is that you have User.new in both your model and the “new” action of your controller, I would do the initialization in one place. I do it in the “new” action.

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

Sidebar

Related Questions

Seeing some strange things; help is being solicited. I have a query, like so:
I'm seeing some very strange behaviour from the Apple Push Notification Servers when the
I'm seeing something very very strange happening in a Flex app I'm maintaining. I've
I'm seeing some very strange sorting behaviour using CaseInsensitiveComparer.DefaultInvariant. Words that start with a
So I'm seeing some strange issues in ie8 with jquery, and assorted javascript files.
I am developing an OpenGL application and I am seeing some strange things happen.
I have a third party component I'm using and I'm seeing some issues with
I have a Spring application running on the Glassfish Webserver and I'm seeing some
I have been trying to design the Undo/Redo functionality in one of my app
I'm getting some very strange date formatting issues in my Silverlight application. My local

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.