I've been messing with my ApplicationController
and somehow broke something. My helper ApplicationHelper::current_settings
serializes @user
so that my JS app can load the current user's data. But suddenly:
undefined method `id' for nil:NilClass
at `@user.id` in app/helpers/application_helper.rb, line 5
However, in my better_errors console, I can see that the variable is set on the controller, just not accessible in the current context:
>> @user
=> nil
>> controller.instance_variable_get("@user")
=> #<Person id: 1, ...>
>> instance_variable_get("@user")
=> nil
I'm setting @organization
the same way, and it's there:
>> @organization
=> #<Organization id: 1 ... >
But for some reason, no sign of @user
!
Here's the helper:
module ApplicationHelper
def current_settings
{
person: {
id: @user.id,
name: @user.to_s
}
}.to_json.html_safe
end
end
And in the controller, it's like:
before_filter :load_user
def load_user
@user = Person.where(some_query).first
end
Any ideas?? Thanks!