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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:06:20+00:00 2026-06-14T00:06:20+00:00

When I submit this form, it is creating 2 identical records in the Members

  • 0

When I submit this form, it is creating 2 identical records in the Members table (the fields_for part of the form). Please help me understand why that is happening.

The basic setup is: a Comp has many Teams and a Team has many Members. When creating a new Team, the first Member created should be the team’s secretary (which means the secretary_flag field in the Members table should be set to TRUE.) This form below is supposed to create a new Team, create the first team member, and mark that team member as the secretary.

The controller:

def new
  @comp = Comp.find(params[:comp_id])    
  @team = @comp.teams.new
  @team.members.build  
end

def create
  @comp = Comp.find(params[:comp_id])
  @team = @comp.teams.create(params[:team])
  if @team.update_attributes(params[:team])
      flash[:success] = "Team added successfully."
      redirect_to new_comp_team_member_path(@comp,@team)
  else
      render 'new' 
  end
end

The form view:

<%= form_for [@comp,@team] do |builder| %>
    <%= builder.label :team_name, "Team name" %>
    <%= builder.text_field :team_name %>        
    <%= builder.fields_for :members do |f| %>
        <%= f.label :member_email, "Email address of team secretary" %>
        <%= f.text_field :member_email %> 
        <%= f.hidden_field :secretary_flag, :value => 1 %>
    <% end %>

<%= builder.submit "Create new team" %> 

<% end %> 

And in my routes:

resources :comps do
    resources :teams do 
        resources :members
    end 
end

And in my models:

comp.rb:

attr_accessible :teams_attributes
has_many :teams, :dependent => :destroy
accepts_nested_attributes_for :teams, :allow_destroy => :true

team.rb:

attr_accessible :members_attributes
belongs_to :comp
has_many :members
accepts_nested_attributes_for :members

member.rb:

 belongs_to :team
  • 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-06-14T00:06:21+00:00Added an answer on June 14, 2026 at 12:06 am

    The solution I figured out was very basic. In my create action I accidentally put:

    if @team.update_attributes(params[:team])
    

    when it should have been:

    if @team.save(params[:team])
    

    I still don’t understand why that would have created 2 identical records though, but it now works.

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

Sidebar

Related Questions

I'm creating a basic form with ajax submit using jquery framework. This is my
WHen I submit this form it downloads the php script that it refers to.
When i submit this form, the values just disappears from the textboxes. I like
Let's say I'm at http://www.domain.com/page.html . I want to submit this form: <FORM METHOD=post
I have this form submit code: Event.observe(window, 'load', init, false); function init() { Event.observe('addressForm',
<form name=vegForm action=veg.aspx > <select onchange='this.form.submit()'> <script type=text/javascript> for (i = 0; i <
I have the following code: echo ' <td> <input type=button name=delete value=X onclick=clearSelection(this.form, '.$type.');this.form.submit();
i have this form to serialize once i click the submit button, <form class=cashier_forms
I have a form, this form has a submit and a cancel button. when
$('form').submit(function(){ this.action=http://www.sitename.com/post; return false; }); having altered the action attribute of the form ,i

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.