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 H.'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
I was trying the conditional form for setting the current tab based on
whether the logged_in? user was an “admin” or a plain “user”. That did
not work. I got the following exception:
NoMethodError in UsersController#edit
undefined method `authorize_admin?’ for UsersController:Class in line 4
which is the current_tab method above. I do not fully understand why.
The current_tab is a class method why can’t it take an argument
containing an instance method?
I got around the above issue by doing this:
class UsersController < ApplicationController
before_filter :login_required
current_tab :clients
def edit
self.class.current_tab :basic_data unless authorize_admin?
end
…
end
So at the method level, I override the current_tab based on desired
condition using the authorize_admin? method. This works.
So my question in the above context is: how do you call an instance
method as an argument to the class method?
Bharat
…
end