Greg Hauptmann wrote:
> Can't I access methods directly after they have been
mixed in?
>
> In the code below I get an error at the marked location
"undefined local
> variable or method `current_user' for
ApplicationController:Class" even
> though I've already mixed in the variable into the
class. Note that
> when I use "current_user.login" in another
place, for example in an
> action in a specific controller, it works fine, but
just not here in the
> ApplicationController directly after the mix in.
>
> Can you spot why at all? Tks in advance.
>
> ============================================
> class ApplicationController < ActionController::Base
> include ActiveRbacMixins::ApplicationControllerMixin
> u = current_user.login <=== ERROR OCCURS
HERE
> end
> ============================================
> module ActiveRbacMixins
> module ApplicationControllerMixin
> def self.included(base)
> base.class_eval do
> protected
> def current_user
> return active_rbac_user unless
active_rbac_user.nil?
> active_rbac_user =
> if session[:rbac_user_id].nil? then
> ::AnonymousUser.instance
> else
>
::User.find(session[:rbac_user_id])
> end
> return active_rbac_user
> end
> end
> end
> end
> end
> ============================================
current_user is an ApplicationController instance method,
which
you can't use in the class context of a class definition.
Perhaps you want to put the setting of u (or u) in a
before_filter.
--
We develop, watch us RoR, in numbers too big to ignore.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk googlegroups.com
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe googlegroups.com
For more options, visit this group at http:
//groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---
|