开发者

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

开发者 https://www.devze.com 2023-02-22 15:42 出处:网络
I\'m using cancan and cells gems in my ruby-on-rails project. How to access can? method from within cell?

I'm using cancan and cells gems in my ruby-on-rails project. How to access can? method from within cell? Than开发者_运维问答ks.


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.


For those who happen to have a custom current_ability() method (in which you can change the name of current_user method and Ability class names):

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号