与命名空间权威人士政策 [英] pundit policies with namespaces

查看:373
本文介绍了与命名空间权威人士政策的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题模型我的应用程序。

应用程序/模型/ question.rb

 类问题< ActiveRecord的::基地
  ...
结束

我使用授权权威人士的宝石。有两个控制器,以做题的一些变化:一为注册用户,一个用于管理

我想为控制器上创建单独的策略。

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

 类QuestionsController< ApplicationController中
   ...
结束

应用程序/政策/ question_policy.rb

 类QuestionPolicy< ApplicationPolicy
  ...
结束

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

 类管理:: QuestionsController<联系:: ApplicationController中
  ...
结束

应用程序/政策/管理/ question_policy.rb

 类管理:: QuestionPolicy<联系:: ApplicationPolicy
  ...
结束

当我尝试使用在管理:: QuestionsController'授权'的方法,它使用的应用程序/政策/管理,从文件夹question_policy.rb类没有。

宝石的文档说,像我上面( https://github.com/描述是应该工作elabs /权威人士#命名空间,政策)。

有人可以帮我吗?


解决方案

我创建了一个GitHub的源$ C ​​$ C的问题,它是这样解释关闭:


  

该文档是指当前未发行的主分支。您可以参照您的Gemfile GitHub的源代码中使用它。


 #的Gemfile
宝石'权威人士',github上:elabs /权威人士
当包安装后您的code应该工作。您可以尽快0.3.0超出切换回发布的版本上的RubyGems。我们还在讨论几个问题,命名空间,但它很快就会来临。

I have Question model in my application.

app/models/question.rb

class Question < ActiveRecord::Base
  ...
end

I'm using 'pundit' gem for authorization. There are two controllers to do some changes in questions: one for registered user, one for admin.

I'm trying to create separate policies for controllers.

app/controllers/questions_controller.rb

class QuestionsController < ApplicationController
   ...
end

app/policies/question_policy.rb

class QuestionPolicy < ApplicationPolicy
  ...
end

app/controllers/admin/questions_controller.rb

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

app/policies/admin/question_policy.rb

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

When I'm trying to use 'authorize' method in Admin::QuestionsController it uses app/policies/question_policy.rb class not from admin folder.

Gem's documentation says that is should work like I described above (https://github.com/elabs/pundit#namespaced-policies).

Can somebody help me with that?

解决方案

I've created issue in github source code and it was closed with such explanation:

The docs refer to the currently unreleased master branch. You can use it by referring to the github source in your Gemfile.

# 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.

这篇关于与命名空间权威人士政策的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆