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.
application_helpers.rborusers_helpers.rb? I take it you've done the necessarybelongs_toandhas_manyassociations?sessions_helper.rb. I have abelongs_toassociation on the households and ahas_manyassociation on the user.