Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

initialize method not called in production mode #1030

Open
pamit opened this issue Jun 28, 2015 · 1 comment
Open

initialize method not called in production mode #1030

pamit opened this issue Jun 28, 2015 · 1 comment

Comments

@pamit
Copy link

pamit commented Jun 28, 2015

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.

@karlingen
Copy link

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants