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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:38:42+00:00 2026-05-11T08:38:42+00:00

My question involves a few different active records class Respondent < ActiveRecord::Base has_many :phone_numbers,

  • 0

My question involves a few different active records

class Respondent < ActiveRecord::Base has_many :phone_numbers, :dependent => :destroy has_many :email_addresses, :dependent => :destroy belongs_to :phone_number, :foreign_key=> 'primary_phone_id' belongs_to :email_address, :foreign_key=> 'primary_email_id' end  class User < Respondent end  class EmailAddress < ActiveRecord::Base belongs_to :respondent has_one :respondent end 

The schema for these tables are

create_table 'email_addresses', :force => true do |t|   t.string   'email'   t.integer  'respondent_id' end  create_table 'respondents', :force => true do |t|   t.string   'first_name'   t.string   'last_name'   t.integer  'primary_email_id'   t.integer  'primary_phone_id'   t.string   'type' end 

What I am trying to accomplish is to have the respondents, and therefore users, capable of having multiple email address but only one primary. For this reason the email record and respondents record link to one another. All of the email address are stored in the email_address record and reference the respondent, and the respondent record has an id to only one email.

In the UserController the following code fails

def create     @user = User.new(params[:user])     @primary_email = EmailAddress.new(params[:primary_email])     User.transaction do       @user.primary_email = @primary_email  <=Undefined Method primary_email=       @user.save!       @primary_email.save!       redirect_to :action => :show, :id => @user     end end 

First, is this even possible what I am doing? How can I modify the code to make this controller code work?

  • 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. 2026-05-11T08:38:43+00:00Added an answer on May 11, 2026 at 8:38 am

    Yes, you just need Respondent to have as associated primary email:

    has_one :primary_email, :class_name => 'EmailAddress' 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class (for logging) which derives from std::ostream. Stripped down, it looks
Almost 6 months ago, I asked a question on stackoverflow Software to help in
In this question, assume all integers are unsigned for simplicity. Suppose I would like
I am now building an iPhone app and it involves core data. One of
Im working with a php form validation, which involves reCAPTCHA as well. Once the
I am attempting to make a program, and it involves a JFileChooser. I am
I'm trying to create a form very similar to the Create event screen of
I have a map. On this map I want to show live data collected
I need to make a small modification to an existing Flash library (Fusion Charts
I wanted to know how to detect which edition of SQL Server 2008 is

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.