Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is current_ability in CanCan's accessible_by (fetching records)?

In the documentation of CanCan it shows how to fetch all accessible records in this way:

@articles = Article.accessible_by(current_ability)

but what is current_ability? I've tried passing the current user which I'm using for authentication and authorization, but I've got this error:

NoMethodError: undefined method `conditions' for #<User:0x1092a3b90>

Any ideas what should I pass to accessible_by or what's wrong here?

like image 834
pupeno Avatar asked Jul 30 '10 05:07

pupeno


1 Answers

CanCan extends ActionController::Base with the current_ability method (among others), which is the class that your ApplicationController should inherit from. So the example code in your question should work as is.

like image 180
Paige Ruten Avatar answered Sep 28 '22 15:09

Paige Ruten