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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:15:10+00:00 2026-06-02T23:15:10+00:00

I am having an issue with the below code in one of my views:

  • 0

I am having an issue with the below code in one of my views:

<% if !@admin.emails.nil? %>
<% @admin.emails.each do |email| %>
  <tr>
    <td><%= email.email %></td>
  </tr>
<% end %>
<% end %>

This produces an error:

undefined method `emails' for nil:NilClass
Extracted source (around line #1):
1: <% @admin.emails.each do |email| %>
2:   <tr>
3:     <td><%= email.email %></td>
4:   </tr>

Admin Controller:

class AdminController < ApplicationController
end
def index
      @emails = Email.all
      respond_to do |format|
       format.html # index.html.erb
       format.xml  { render :xml => @emails }
     end
end

Email Model:

class Email < ActiveRecord::Base
  attr_accessible :email
  belongs_to :admin
  email_regex = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i

  validates :email, :presence   => true,
                    :length     => { :maximum => 250 },
                    :format     => { :with => email_regex },
                    :uniqueness => { :case_sensitive => false }

end

Admin Model:

class Admin < ActiveRecord::Base
  has_many :emails
end

Any idea what could be wrong?

  • 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-02T23:15:11+00:00Added an answer on June 2, 2026 at 11:15 pm

    Your index method is not inside the AdminController… 🙂

    And it defines @emails rather than @admin.

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

Sidebar

Related Questions

I am having an issue with the below code in one of my views:
I'm having an issue with one of my conditional statements. The code below is
I'm having an issue in IE9 with onbeforeunload -- when the code below is
I am having an issue on mouse hover effect. My code is below and
I'm having a (probably super simple) issue. The code below is supposed to _POST
I am having an issue in someone else's code. I have code in one
I'm trying to learn C++ currently, but I'm having issues with the code below.
Hello everyone I'm currently having 2 issues with the code below: Upon return of
Having an issue with traversing in jQuery.. hopfully an easy one..but I'm banging my
A client is having an issue running java2ws on some of their code, which

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.