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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:05:29+00:00 2026-06-10T22:05:29+00:00

I am trying to create an activity feed with the most recent activities from

  • 0

I am trying to create an activity feed with the most recent activities from my TrainingSession model.

class User
  has_many :training_sessions
end

class TrainingSession
  belongs_to :user
end

The problem is that I am trying to access a user’s data in the view page (mainly the user’s name) by instantiating an object from the TrainingSessions database table, as shown below:

<% @training_sessions.each do |training_session| %>
<%= training_session.user_id %>

The problem is that, although I successfully get the user’s id, I cannot call, for example:

training_session.user_id.name

… otherwise I get the NoMethodError shown below:

undefined method `first_name' for 2:Fixnum

so my question is … how can I access the user’s data from the TrainingSession’s object?

any help would be much appreciated. Pretty stumped on this one.

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

    The reason that you get a “undefined method `name’ for nil:NilClass”-error is that some training sessions do not belong to a user. The solution is to cleanup your database:

    DELETE FROM training_sessions WHERE user_id IS NULL
    

    If it is expected behavior to have training sessions that don’t belong to a user, you have to check that the user is not nil in your loop:

    <% @training_sessions.each do |training_session| %>
      <% unless training_session.user.nil? %>
        <%= training_session.user.name %>
      <% end %>
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create an Activity class from a string and pass it
I'm trying create a log specifically for logging user account activity. I created this
I'm trying to create an activity feed list in redis using the redis-node library
I'm trying to create a list fragment activity like this : public class FluxListeFragment
I am trying to create a searchable activity however when I get to this
Trying to create Database as follows: USE Master GO IF NOT EXISTS(SELECT [Name] FROM
I'm trying to create a camera activity for taking photos to be OCR'd. Here's
I'm trying to create a setup activity for my Android application which my users
So what I am trying to create is an activity that displays an image
I am trying to create a PreferenceScreen but i want the Activity design like

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.