On Apr 2, 10:33 pm, Bharat Ruparel <[email protected]>
wrote:
> I have a file call authentication.rb in rails root/lib directory which
> has the following method defined amongst others:
>
> module Authentication
>   ...
>   def authorize_admin?
>     logged_in? && has_role?('admin')
>   end
>   ...
> end
>
> This module is included into application.rb as follows:
>
> class ApplicationController < ActionController::Base
>
>   # Ryan's stripped down Authentication module from
> Restful_Authentication
>   include Authentication
>   # Tim Harper's RoleRequirement module from his plugin
>   include RoleRequirementSystem
>
> end
>
> I am also using Ryan Heath's excellent navigation_helper plugin which
> has a "current_tab" class method.  You set the current_tab at the
> controller level as follows:
>
> class UsersController < ApplicationController
>
>   before_filter :login_required
>   current_tab(self.authorize_admin? ? :clients : :basic_data)
>   ...
> end
>

If you don't understand why this doesn't work, then you probably don't
understand when this code runs. This code runs when the class is
loaded from users_controller.rb. In particular self is the class
UsersController, so you can't call authorize_admin? on it, since that
is an instance method and you don't have an instance of
UsersController.

In production this code only executes once (when the app starts), ie
there is no request or current user - clearly you can't be doing  user
specific things at this point.

Fred


--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to