How to access the "may"? method from inside the cell?

I use cancan and cells gems in my ruby-on-rails project. How to access the can? method can? from inside the cell? Thanks.

+7
source share
2 answers

I had to do just that. Try

 class MyCell < Cell::Rails include CanCan::ControllerAdditions end 

If you are also using Devise, I should have done this:

 class MyCell < Cell::Rails include CanCan::ControllerAdditions include Devise::Controllers::Helpers Devise::Controllers::Helpers.define_helpers(Devise::Mapping.new(:user, {})) end 

#define_helpers will add helper methods like current_user and user_signed_in? to the cell.

+12
source

For those who have their own current_ability() method (in which you can change the name of the current_user method and the names of the skill class):

 class OrderCell < Cell::Rails include CanCan::ControllerAdditions delegate :current_ability, :to => :controller end 
+4
source

All Articles