herited_resources 和 cancan 冲突
与inherited_resources 和Ryan Bates 的cancan gem 存在冲突。
我有一些简单的控制器
class IssuesController < InheritedResources::Base
respond_to :html
load_and_authorize_resource
def tag
@issues = Issue.tagged_with(params[:tag]).recent.paginate(:page => params[:page])
end
protected
def collection
@issues = end_of_association_chain.recent.paginate(:page => params[:page], :per_page => Settings.per_page_defaults.issues)
end
end
和路线
resources :issues do
collection do
get "tag/:tag" => "issues#tag", :as => "tags"
end
end
一切看起来都是正确的,但在尝试请求 http://localhost:8080/issues /标签/标签1 我看到
ActiveRecord::RecordNotFound in IssuesController#tag
Couldn't find Issue without an ID
从控制器中删除 load_and_authorize_resource 后 - 一切正常,但我需要访问控制。
知道如何解决这个问题吗?
There are conflict with inherited_resources and Ryan Bates's cancan gem.
I have some simple controller
class IssuesController < InheritedResources::Base
respond_to :html
load_and_authorize_resource
def tag
@issues = Issue.tagged_with(params[:tag]).recent.paginate(:page => params[:page])
end
protected
def collection
@issues = end_of_association_chain.recent.paginate(:page => params[:page], :per_page => Settings.per_page_defaults.issues)
end
end
and route
resources :issues do
collection do
get "tag/:tag" => "issues#tag", :as => "tags"
end
end
Everything looks correct, but on attempt to request http://localhost:8080/issues/tag/tag1
i see
ActiveRecord::RecordNotFound in IssuesController#tag
Couldn't find Issue without an ID
After removing load_and_authorize_resource from controller - everything works fine, but i need access control.
Any idea how to solve this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用load_and_authorize_resource:例外=> :标记。请注意,这不适用规则。如果您需要应用某些内容,请改用
authorize!
。use
load_and_authorize_resource :except => :tag
. Note that this wont apply rules. If you need to apply some useauthorize!
instead.