List Info

Thread: Access to mixed in method straight after its been mixedin???




Access to mixed in method straight after its been mixedin???
user name
2006-09-07 11:17:46
Hi,

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
============================================


-- 
Posted via http://www.ruby-forum.com
/.

--~--~---------~--~----~------------~-------~--~----~
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-talkgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribegooglegroups.com
For more options, visit this group at http:
//groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---

Access to mixed in method straight after its been mixedin???
user name
2006-09-07 12:49:17
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-talkgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribegooglegroups.com
For more options, visit this group at http:
//groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )