Reputation: 544
I have a method that checks for a boolean value on a table, and it returns false in my Users views (everywhere else it returns true). I am having trouble understanding why it is accessible, but returns false.
My code:
Application Controller:
protected
def current_user
@current_user ||= User.find_by_id(session_user_id) if session_user_id
end
helper_method :current_user
def current_customer
if current_user.customer and current_user.customer.master?
else
current_user.customer
end
end
helper_method :current_customer
Application helper method:
def customer_helper?
(current_user && current_user.customer.boolean_value?)
end
the customer_helper? method returns false in all of my Users views, even though my UsersController inherits from ApplicationController.
Any advice or help would be greatly appreciated.
Upvotes: 1
Views: 1298
Reputation: 4996
current_user
is nil
within the helper method. I assume you are accessing this in a view where current_user has been exposed to the view from the controller. The attributes exposed to the view must be passed into the helper methods; they are are not automatically made available there.
If my assumptions are correct then your helper method should look something like this.
def customer_helper?(current_user)
(current_user && current_user.customer.boolean_value?)
end
You will then need to update the call to customer_helper?
in your view to pass in the current_user.
Upvotes: 1