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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:52:51+00:00 2026-06-11T22:52:51+00:00

I am new to Rails and Ruby and actually it’s my first web language.

  • 0

I am new to Rails and Ruby and actually it’s my first web language. This isn’t my first project but it’s the bigest so far and I am having trouble with a certain page (the “home” page).

The error is:

NoMethodError in Home#index undefined method `avatar' for nil:NilClass

Extracted source (around line #1):

1: <%= image_tag current_user.avatar.url(:thumb) %>
2: <ul>
3:   <li><b>Name:</b><%= current_user.name %></li>
4:   <li><b>Username:</b><%= current_user.username %></li>

So it doesn’t like my attributes 🙁 What should I do in this situation? Where should I look first? Is this a controller problem?

  • 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-11T22:52:52+00:00Added an answer on June 11, 2026 at 10:52 pm

    The problem is that current_user is returning nil.

    Take a look at the error

    NoMethodError in Home#index undefined method `avatar' for nil:NilClass
    

    Ruby is saying that you are trying to execute an instance method avatar on the nil object. After looking at your code, you should be able to tell that you are calling avatar on the return value of current_user so you can deduce that current_user is returning nil instead of the user.

    Per the comments:

    To solve this you will need to first determine if there is a current_user. Then and only then do you try to display a users avatar or the users other attributes (name, username …)

    Some people do not like logic in the views, I tend to follow this practice.

    To avoid this, you could: create a view helper that contains the logic. This helper may or may not display/return data about a user.

    Something along the lines of if current_user ...

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

Sidebar

Related Questions

Im new to both ruby and rails, but have experience with java, javascript and
I'm brand new to ruby and rails and I'm having trouble creating a sign-out
So, I just moved to new project that is built on Ruby on Rails.
I'm new to Ruby on Rails and I'm sure this question is pretty stupid,
I am new to Rails / Ruby. I am working on a project where
I'm fairly new to Ruby on Rails and actually entirely new to website mailing.
I am new to ruby and rails and I am having difficulty conceptualizing the
New to both Ruby and Rails but I'm book educated by now (which apparently
Hey, I'm new to Rails and Ruby in general. I was wondering if it's
I'm new to ruby/rails and trying to build a simple Projects / Tags app

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.