2014-07-16 42 views
2

我在我的应用程序中有问题模型。权威政策与命名空间

应用程序/模型/ question.rb

class Question < ActiveRecord::Base 
    ... 
end 

我使用的是 '权威人士' 的宝石进行授权。有两个控制器可以对问题进行一些更改:一个用于注册用户,另一个用于管理员。

我试图为控制器创建单独的策略。

应用程序/控制器/ questions_controller.rb

class QuestionsController < ApplicationController 
    ... 
end 

应用程序/政策/ question_policy.rb

class QuestionPolicy < ApplicationPolicy 
    ... 
end 

应用程序/控制器/管理/ questions_controller.rb

class Admin::QuestionsController < Admin::ApplicationController 
    ... 
end 

应用程序/ policies/admin/question_policy.rb

class Admin::QuestionPolicy < Admin::ApplicationPolicy 
    ... 
end 

当我试图在Admin :: QuestionsController中使用'authorize'方法时,它使用的app/policies/question_policy.rb类不是来自admin文件夹。

宝石的文档说应该像我上面描述的那样工作(https://github.com/elabs/pundit#namespaced-policies)。

有人可以帮我吗?

回答

0

我创建问题github上的源代码,并用这样的解释关闭:

该文档是指当前未发行的主分支。您可以通过引用Gemfile中的github源来使用它。

# Gemfile 
gem 'pundit', github: 'elabs/pundit' 
A bundle install later your code should work. 

You can switch back to a released version on Rubygems as soon as 0.3.0 is out. We're still  discussing a few namespacing issues, but it will come soon. 
+0

此解决方案适用于我。 – jizak

0

如果有人还在寻找这个功能,我需要它,以及对ActiveAdmin和我的最终用户面临的网站之间的分裂授权。我为controller-based namespaced authorizations(您的策略将起作用)构建了一个与Pundit兼容的gem,并且我打算遵循为专家发布的任何功能。它还包括一个ActiveAdmin适配器。