How to access 'can?' method from within cell?

后端 未结 2 1676
猫巷女王i
猫巷女王i 2021-02-09 08:30

I\'m using cancan and cells gems in my ruby-on-rails project. How to access can? method from within cell? Thanks.

2条回答
  •  猫巷女王i
    2021-02-09 09:20

    I've had to do exactly this. Try

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

    If you're also using Devise, I had to do 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 such as current_user and user_signed_in? to the cell.

提交回复
热议问题