InheritedResources/CanCan 问题

发布于 2024-12-29 03:24:41 字数 496 浏览 5 评论 0原文

使用 InheritedResouces 时,CanCan 在控制器中的索引操作方面表现得非常奇怪。如果我有

can :read, Question do |question|
  false
end

ability.rb - 它会授予对操作的访问权限,尽管块的返回值。如果我删除此行 - “您无权访问此页面。”。 控制器代码如下:

# encoding: utf-8
class QuestionsController < InheritedResources::Base
  actions :all, :except => [:edit, :update]

  before_filter :authenticate_user!,  :except => [:show]
  load_and_authorize_resource         :except => [:show]
end

CanCan behaves really strange with index action in controller while using InheritedResouces. If i have

can :read, Question do |question|
  false
end

in ability.rb - it grants access to the action despite on block's returning value. If i remove this line - "You are not authorized to access this page.".
Controller code below:

# encoding: utf-8
class QuestionsController < InheritedResources::Base
  actions :all, :except => [:edit, :update]

  before_filter :authenticate_user!,  :except => [:show]
  load_and_authorize_resource         :except => [:show]
end

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

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

发布评论

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

评论(1

巾帼英雄 2025-01-05 03:24:41

我不太确定,但尝试一下:

class QuestionsController < InheritedResources::Base
  actions :index, :new, :create, :destroy, :show
  ...

: except 前一段时间有一个错误。 https://github.com/railsbp/rails_best_practices/issues/66

尝试更新 InheritedResources gem。

I'm not really sure but try with:

class QuestionsController < InheritedResources::Base
  actions :index, :new, :create, :destroy, :show
  ...

There was a bug some time ago with :except. https://github.com/railsbp/rails_best_practices/issues/66.

Try updating InheritedResources gem.

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