如何访问“可以?”细胞内的方法?

发布于 2024-10-31 01:08:16 字数 128 浏览 1 评论 0原文

我在 ruby​​-on-rails 项目中使用 cancancells gem。 如何从单元格内访问can?方法? 谢谢。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

瀞厅☆埖开 2024-11-07 01:08:16

我必须这样做。尝试

class MyCell < Cell::Rails

  include CanCan::ControllerAdditions

end                                        

如果您也在使用 Devise,我必须这样做:

class MyCell < Cell::Rails

  include CanCan::ControllerAdditions
  include Devise::Controllers::Helpers
  Devise::Controllers::Helpers.define_helpers(Devise::Mapping.new(:user, {}))

end                                        

#define_helpers 将添加帮助器方法,例如 current_user 和 user_signed_in?到细胞。

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.

御弟哥哥 2024-11-07 01:08:16

对于那些碰巧有自定义 current_ability() 方法的人(您可以在其中更改 current_user 方法的名称和能力类名称):

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文