Re: Can't manage user model from rails_admin with CanCanCan

205 views
Skip to first unread message

Bryan Rite

unread,
May 5, 2014, 11:33:33 AM5/5/14
to jamet....@gmail.com, canc...@googlegroups.com
Hi Ludovic,

I don’t use RailsAdmin myself so I’m not 100% sure whats going on, but we don’t specifically check for a User::Permission model in CanCanCan. Your ability file does look fine so I would hazard a guess that the `User::Permission` class is being called from somewhere else.



On May 3, 2014, at 9:55 AM, jamet....@gmail.com wrote:

> Hello everybody,
>
> I have trouble with rails_admin since a month, I don't find the solution.
>
> I have an User model and an Admin model. I use CanCanCan 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 CanCanCan 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 seems to be ok
>
> 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
> Thanks for your help
> Regards,
> Ludovic
>
> --
> You received this message because you are subscribed to the Google Groups "cancancan" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to cancancan+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

signature.asc
Reply all
Reply to author
Forward
0 new messages