Question

I have an User model and an Admin model. I use CanCan and Devise for both. I use rails_admin but when I want to list or edit users from my rails_admin I got a mysterious error.

Processing by RailsAdmin::MainController#index as HTML
Parameters: {"model_name"=>"user"}
Admin Load (0.4ms)  SELECT `admins`.* FROM `admins` WHERE `admins`.`id` = 1 ORDER BY `admins`.`id` ASC LIMIT 1
Completed 500 Internal Server Error in 9ms

NameError (uninitialized constant User::Permission):

I think User::Permission is from CanCan but I'm not sure.

I got almost the same error when I try to edit many others models that belong to a user. But the error change :

ActionView::Template::Error (uninitialized constant User::Permission):

My Ability model

class Ability
    include CanCan::Ability

    def initialize(resource)

        # Define guest user role
        if !resource
            resource = User.new
            resource.role = "guest"
        end

        # Authorizations for admins
        if resource.class == Admin 
            can :dashboard
            can :access, :rails_admin
            can :manage, User # I delete all models for the topic
            can :manage, Piggybak.config.manage_classes.map(&:constantize)
            Piggybak.config.extra_abilities.each do |extra_ability|
                can extra_ability[:abilities], extra_ability[:class_name].constantize
            end
        end

        # Authorizations for users
        if resource.class == User
            case resource.role
                # Guest
                when "guest"
                    can :create, User
                # Freemium
                when "member"
                    can :manage, User

            end
        end
    end
end
Was it helpful?

Solution

I reinstall all my gems : rails_admin, CanCan and Devise. It works ! Very strange error...

OTHER TIPS

I recommend you update CanCan to CanCanCan. This is a folk of cancan which is more maintained.

You probably forgot to run bundle install after adding in CanCan

check you User model , find attr Permission. delete it if that is useless.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top