Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I test CanCan in the console?

I need to check :read? on an object in the console, how can I do this?

like image 671
AKWF Avatar asked May 16 '11 14:05

AKWF


People also ask

Can can can authorize?

CanCan is an authorization library for Ruby on Rails which restricts what resources a given user is allowed to access. All permissions are defined in a single location (the Ability class) and not duplicated across controllers, views, and database queries.

Can Can gem Ruby?

CanCanCan is an authorization library for Ruby and Ruby on Rails which restricts what resources a given user is allowed to access.


1 Answers

You need to setup Ability object:

ability = Ability.new(current_user_object) 

Now you check authorization:

ability.can? :read, object_to_be_checked 

current_user_object: User object for which you want to check authorization

object_to_be_checked: is object on which you want to check authorization

like image 70
AKWF Avatar answered Sep 21 '22 15:09

AKWF