heartcombo / devise

Flexible authentication solution for Rails with Warden.
http://blog.plataformatec.com.br/tag/devise/
MIT License
24k stars 5.55k forks source link

Can't access current_user in a controller #1732

Closed betjamin closed 12 years ago

betjamin commented 12 years ago

I can access this fine in my views, but when I try to access the current user in my controller I'm receiving the following:



undefined local variable or method `current_user' for AssessmentsController:Class```

I'm running Devise 1.5.0. My ancestors stack is as follows:

`[#<Class:0x007fae1f1126f8>, #<Module:0x007fae201eb8f8>, #<Module:0x007fae1f486578>, SessionsHelper, RisksHelper, RcmHelper, MHelper, DeviseHelper, CoralHelper, ControlsHelper, ControlCommentsHelper, CommentsHelper, AutocompleteHelper, AuditsHelper, AssessmentsHelper, AreasHelper, ApplicationHelper, #<Module:0x007fae1bc8c028>, ActionDispatch::Routing::RouteSet::MountedHelpers, #<Module:0x007fae1b25ec40>, ActionDispatch::Routing::Helpers, #<Module:0x007fae1bbbfb90>, ActionView::Base, OnTheSpot::Helpers, Devise::Controllers::UrlHelpers, Sprockets::Helpers::RailsHelper, ActionView::Helpers, ActionView::Helpers::TranslationHelper, ActionView::Helpers::RenderingHelper, ActionView::Helpers::RecordTagHelper, ActionController::RecordIdentifier, ActionView::Helpers::OutputSafetyHelper, ActionView::Helpers::NumberHelper, ActionView::Helpers::JavaScriptHelper, ActionView::Helpers::FormOptionsHelper, ActionView::Helpers::FormHelper, ActionView::Helpers::FormTagHelper, ActionView::Helpers::TextHelper, ActionView::Helpers::SanitizeHelper, ActionView::Helpers::DebugHelper, ActionView::Helpers::DateHelper, ActionView::Helpers::CsrfHelper, ActionView::Helpers::ControllerHelper, ActionView::Helpers::CacheHelper, ActionView::Helpers::AtomFeedHelper, ActionView::Helpers::AssetTagHelper, ActionView::Helpers::AssetTagHelper::StylesheetTagHelpers, ActionView::Helpers::AssetTagHelper::JavascriptTagHelpers, ActionView::Helpers::UrlHelper, ActionView::Helpers::TagHelper, ActionView::Helpers::CaptureHelper, ActionView::Helpers::ActiveModelHelper, ActiveSupport::Benchmarkable, ActionDispatch::Routing::UrlFor, ActionDispatch::Routing::PolymorphicRoutes, ERB::Util, ActionView::Context, ActionView::CompiledTemplates, Object, JSON::Ext::Generator::GeneratorMethods::Object, ActiveSupport::Dependencies::Loadable, Kernel, BasicObject] [AssessmentsController, ApplicationController, #<Module:0x007fae1b25ec40>, ActionDispatch::Routing::Helpers, #<Module:0x007fae1bbbfb90>, ActionController::Base, OnTheSpot::ControllerExtension, Devise::Controllers::UrlHelpers, Devise::Controllers::Helpers, ActionDispatch::Routing::RouteSet::MountedHelpers, ActiveRecord::Railties::ControllerRuntime, ActionController::Compatibility, ActionController::ParamsWrapper, ActionController::Instrumentation, ActionController::Rescue, ActiveSupport::Rescuable, ActionController::HttpAuthentication::Token::ControllerMethods, ActionController::HttpAuthentication::Digest::ControllerMethods, ActionController::HttpAuthentication::Basic::ControllerMethods, ActionController::RecordIdentifier, ActionController::DataStreaming, ActionController::Streaming, ActionController::ForceSSL, ActionController::RequestForgeryProtection, AbstractController::Callbacks, ActiveSupport::Callbacks, ActionController::Flash, ActionController::Cookies, ActionController::MimeResponds, ActionController::ImplicitRender, ActionController::Caching, ActionController::Caching::Fragments, ActionController::Caching::ConfigMethods, ActionController::Caching::Sweeping, ActionController::Caching::Pages, ActionController::Caching::Actions, ActionController::SessionManagement, ActionController::ConditionalGet, ActionController::Head, ActionController::Renderers::All, ActionController::Renderers, ActionController::Rendering, ActionController::Redirecting, ActionController::RackDelegation, AbstractController::Logger, ActionController::UrlFor, AbstractController::UrlFor, ActionDispatch::Routing::UrlFor, ActionDispatch::Routing::PolymorphicRoutes, ActionController::HideActions, ActionController::Helpers, AbstractController::Helpers, AbstractController::AssetPaths, AbstractController::Translation, AbstractController::Layouts, AbstractController::Rendering, AbstractController::ViewPaths, ActionController::Metal, AbstractController::Base, ActiveSupport::Configurable, Object, JSON::Ext::Generator::GeneratorMethods::Object, ActiveSupport::Dependencies::Loadable, Kernel, BasicObject]`
josevalim commented 12 years ago

As the error message says, apparently you are trying to call the current_user in the class, it certainly won't be available at the class scope.