Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devise::Controllers::Helpers #1

Open
danielgrippi opened this issue Jun 25, 2011 · 4 comments
Open

Devise::Controllers::Helpers #1

danielgrippi opened this issue Jun 25, 2011 · 4 comments

Comments

@danielgrippi
Copy link

Including Devise::Controllers::Helpers in ApplicationController.rb resolves the Devise-specific before_filter :authenticate_user!, but I'm still not able to use the current_user method in my controllers. This is what happens when I try calling it:

undefined local variable or method `current_user' for #<#<Class:0x00000100f44628>:0x00000100f3d648>

It seems as if the define_helpers method isn't getting triggered in Devise. Any ideas?

@danielgrippi
Copy link
Author

Yep, looking at the define_helpers(mapping) a little further, it looks like the helper_methods only get added when action_controller gets loaded: https://github.com/plataformatec/devise/blob/master/lib/devise/controllers/helpers.rb#L56

@danielgrippi
Copy link
Author

my quick and dirty fix for now -- placing this method in application_helper:

def current_user
   @current_user ||= warden.authenticate(:scope => :user)
end

@MikeSofaer
Copy link
Owner

Weird. I poked around at this locally, and didn't get the problem, Devise works fine for me with just the include.

That's a weird error message to get, though, I'd expect to see the class name. Are you calling it in an instance method of a controller that inherits from ApplicationController?

@rsofaer
Copy link
Collaborator

rsofaer commented Jun 25, 2011

Can you call define_helpers on the controller class? Then just call helper_method yourself to put it in the views.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants