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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:18:06+00:00 2026-06-17T06:18:06+00:00

When i execute the command to appear the column of user when have the

  • 0

When i execute the command to appear the column of user when have the many comments this error:

      <% post.comments.each do |comment|   %>
        <div id="comments" >
          <%= comment.user.email if comment.user.email != nil %>
               <%= comment.comment %>
        </div>
NoMethodError in Posts#index

Showing /Users/overallduka/Blog1/app/views/posts/index.html.erb where line #50 raised:

undefined method `email' for nil:NilClass
Extracted source (around line #50):

The comments model have belongs_to user and the user model have has_many comments, as right this, but i dont identifie the problem, i check and all my comments have user_id , please some solution please.

  • 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-17T06:18:07+00:00Added an answer on June 17, 2026 at 6:18 am

    The problem is that at least one of the comments on your post object has a nil value for the user association. You’re checking that email is not nil, but you’re not checking whether user itself is nil (which is what is triggering the NoMethodError).

    As a start, I would change this line:

    <%= comment.user.email if comment.user.email != nil %>
    

    to:

    <%= comment.user && comment.user.email %>
    

    This is a handy pattern in ruby which first checks that comment.user is defined, and if it is defined returns the second argument, i.e. comment.user.email. If comment.user is not defined (or nil, or false) then the second argument is not evaluated, and the return value is nil (so if no user is defined, then comment.user.email is never evaluated so you don’t get an error).

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

Sidebar

Related Questions

I'm trying to execute command prompt commands and read the output in C#. This
I execute the command below to revoke a user's permissions to execute a particular
How can i execute a command prompt command from ie9? I know that this:
I have execute-extended-command bound to alt+a. So when in minibuffer, when i press it,
Suppose i have this sql statement and I have executed a sql command to
I use exec() to execute command, either linux or windows. How do you execute
How can I execute a command in qmake after everything is finished? QMAKE_POST_LINK doesn't
How can I execute a command line from within a WiX script? I want
I need to execute a command 100-200 times, and so far my research indicates
When I execute the command adb logcat while running the android emulator, all of

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.