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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:35:36+00:00 2026-05-24T02:35:36+00:00

I have a User model that has_many parents. I want that user model to

  • 0

I have a User model that has_many parents.
I want that user model to have one father and one mother.

So my class Parent belongs_to user

Currently I have

class User < ActiveRecord::Base
  has_many :parents

  has_one :father, :class_name => 'Parent', :foreign_key => 'user_id', :conditions => {:type => 'male'}
  has_one :mother, :class_name => 'Parent', :foreign_key => 'user_id', :conditions => {:type => 'female'}
end

class Parent < ActiveRecord::Base
  belongs_to :user
end

The problem is in my controller.

...
def edit
  @user = User.find(params[:id])
  @user.mother = Parent.new(:type => 'female')
  @user.father = Parent.new(:type => 'male')
...

When I go into the edit, it creates and throws the 2 parents into the database without even having changed anything in the form. For example, when I click edit on a user, I go to the edit page. When I look into the database, they’re already created.

My form looks like so:

= form_for @user do |f|
  = f.fields_for :father do |father_form|
    etc...
  = f.fields_for :mother do |mother_form|
    etc...

I’ve tried doing something alone the lines of this in my controller:

...
@user.parents.build(:type => 'male')
@user.parents.build(:type => 'female')
...

But the form doesn’t show up.

Any help would be greatly appreciated.

  • 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-24T02:35:36+00:00Added an answer on May 24, 2026 at 2:35 am

    Try to use

    @user.build_father(:type => 'male')
    @user.build_mother(:type => 'female')
    

    instead of

    @user.mother = Parent.new(:type => 'female')
    @user.father = Parent.new(:type => 'male')
    

    in your action

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

Sidebar

Related Questions

I have a User model that has_many projects. The Project model belongs_to the User
I have a model User, that has_many belongings (a belonging belongs_to a user). I
Back-end: I have a model (User) that has_many of another model (ContactPreference). Front-end: An
I have a model that looks like this: class Invite(models.Model): user = models.ForeignKey(User) event
I have the parent model of user and user has_many :events . From the
I have a model User that has defined in user.rb many relationships like has_many
I have such terrible models: class ParentalRelation < ActiveRecord::Base belongs_to :parent belongs_to :student belongs_to
I have 3 model the first user.rb: class User has_many :boards, dependent: :destroy has_many
I have a user model that can follow some tags User has_many :tag_followings has_many
So I have a User model that :has_many other models like Documents, Videos, Posts

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.