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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:45:21+00:00 2026-05-27T15:45:21+00:00

In my application I have a very simple association. A User has_many Emails, this

  • 0

In my application I have a very simple association. A User has_many Emails, this association works as expected with create/update/delete.

How ever when I attempt to display the information this is where things become some what difficult.

In my controller I have the following bit of code:

def prospective_user
    @users = Account::User.all_by_user_status(0)     
    @users.each do |u|
        u.email = u.email.get_primary_email
    end
end

What this should do is create an instance of the Account::Email model with a single record.

The method get_primary_email looks like this:

def self.get_primary_email
    first :conditions => ["is_primary = 1"]
end

The issue I am seeing is with in my view, I am getting the exception below. This is a bit confusing as I am not looping over the email object.

undefined method each' for #<Account::Email:0x7fcc3a5c49d8>

The code I am using to test with is this:

<% @users.each do |u|%>
    <p>
        <%=debug(u.email)%>
    </p>
<% 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-27T15:45:22+00:00Added an answer on May 27, 2026 at 3:45 pm

    Do something like that instead:

     class User < ActiveRecord::Base
       has_many :emails
       has_one  :primary_email, :class_name => 'Email',
                                :conditions => { is_primary: 1 }
     end
    

    Then you can call user.primary_email directly

    # your controller
    def prospective_user
      @users = Account::User.includes(:primary_email).where(:status => 0)
    end
    
    # your view
    <% for user in @users %>
      <%= user.primary_email %>
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple Velocity application that works on Linux and MacOS and
I have a very simple WPF application in which I am using data binding
I have a very simple .net application for testing SMTP on .net. But i
We have a very simple ASP.NET web application comprising mostly static content and a
I have built a very simple blog application using Ruby on Rails. New to
Very simple Qt GUI application: On the scene I have multiple circles implemented as
My use case is very simple : I have a GUI application, and inside
in my application I made a very simple binding. I have a NSMutableArray bound
I have a simple iPhone application that is very similar to the Page Control
I have developed a simple location aware iPhone application which is functionally working very

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.