cancan
cancan copied to clipboard
initialize method not called in production mode
Hi,
I'm trying to user multi-role authorization with cancan. In development mode everything is perfect! A typical user can have both 'normal' and 'moderator' roles which each has defined permissions. And I can debug and log what happens in initialize method. The permissions are concatenated for this user.
But in production mode, this does not work! I cannot debug ability.rb. And even I authorize the user with all permissions, he cannot access the permissions of the 2nd role:
def initialize(user)
can :manage, :all
...
end
These are the methods in application_controller.rb
def current_ability
cache_key = (current_user.present? ? "#{current_user.cache_key}::ability" : "unsigned_user::ability")
@current_ability = Rails.cache.fetch(cache_key) do
super
end
end
def load_permissions
if user_signed_in?
@current_permissions = Rails.cache.fetch("#{current_user.cache_key}::permissions") do
temp = Array.new
current_user.roles.each do |role|
role.permissions.map{ |p| temp << [p.subject_class, p.action] }
end
temp
end
end
end
Help me! Thank you.
https://github.com/CanCanCommunity/cancancan