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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:41:12+00:00 2026-06-11T13:41:12+00:00

I have a helper that checks if a user is signed in or not:

  • 0

I have a helper that checks if a user is signed in or not:

def signed_in?
  !current_user.nil?
end

I also have a helper that allows views and controllers to access the user object by checking the session:

def current_user
  @current_user ||= User.find_by_session(session[:user_id])
end

In one of my controllers, it works fine to pull up the user object

  def index
    @households = current_user.households.all
    @household = current_user.households.build

    respond_to do |format|
      format.html
      format.xml { render xml: @households }
    end
  end

The other controller, however, chokes on the current_user helper when it tries to call the households relation:

def home
  @households = current_user.households.all
  @household = current_user.households.build

  respond_to do |format|
    format.html
    format.xml { render xml: @households }
  end
end

The error:

undefined method `households' for nil:NilClass

I’m pretty stumped and could not find any posts related to this specific subject. I’m new to rails though. Am I asking this question in the wrong way?

Thanks in advance.

  • 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-11T13:41:13+00:00Added an answer on June 11, 2026 at 1:41 pm

    Try to include module into your second controller.

    For example, helper module looks like this:

    module UserHelper
      def current_user
        @current_user ||= User.find_by_session(session[:user_id])
      end
    end
    

    Then include it into your controller:

    class YourController < ApplicationController
      include UserHelper
    
      def home
        @households = current_user.households.all
        @household = current_user.households.build
    
        respond_to do |format|
          format.html
          format.xml { render xml: @households }
        end
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a rails helper in my application_helper.rb file that looks like this: def
I have a check_user_access_control before_filter in my ApplicationController that checks the logged user's roles
I have a helper class that I want to display a UIAlertView then will
I have a helper class that should only ever run in a background thread.
I have an Html Helper that converts an Enum into a SelectList like so:
I have a helper class that is passed an array of values that is
I have a view helper that manages generating thumbnails for images. The images are
I have a markdown helper that looks like this in application_helper.rb . How would
I currently have a helper class that I am using to obfuscate a static
I have a REST service and I want to have a helper class that

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.