user ||= User.new # guest user (not logged in)
if (user.role == ‘admin’ && user.site_name == current_subdomain_name)
can :manage, :all
else
can :read, :all
current_subdomain_name should be the name of the subdomain on which user is browsing. But i could not get it.
I have tried the following was but could not succeed.
setting a current_subdomain_name as a global variable in the application controller and using the global variable. (using ruby debugger i found that the global variable is having nil in it)
i have a method current_subdomain_name in the application helper which returns what i wanted, I included the same inside the ability model and tried to use the method . But was getting error .
writting a mehod in controller such that it returns what i wanted and use the same in the model.Still could not succeed.
See if this works
class Ability
include CanCan::Ability
def initialize(user, subdomain) #subdomain should now contain the current subdomain
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new # guest user (not logged in)
if user.admin?
can :manage, :all
else
can :read, :all
end
end
end