【问题标题】:Rails 4 - Pundit - policies not workingRails 4 - Pundit - 政策不起作用
【发布时间】:2016-07-02 02:16:30
【问题描述】:

我正在尝试弄清楚如何在我的 Rails 4 应用程序中使用 Pundit。

我有一个项目模型,其中有一个项目控制器,其中包含一个新操作:

def new
# a bunch of stuff in the new action that I don't think is very relevant here

end

然后,我的策略文件夹中有一个项目策略:

def new?
        false
        # create?
    end

    def create?
        false

    end

我希望我不能在我的网站中输入 url/projects/new,因为政策不允许这样做。但是,我可以,并且表单呈现并且我可以保存它。

有人知道我在设置时做错了什么吗?

【问题讨论】:

    标签: ruby-on-rails pundit policies


    【解决方案1】:

    因为您没有在问题中提及它们,所以需要检查的几件事:

    1. include Pundit添加到控制器

    2. new 操作和create 操作中添加authorize [model_instance]

    官方https://github.com/elabs/pundit应该会给你很多指导。

    【讨论】:

    • 谢谢,我没有把authorise的拼写美国化。
    猜你喜欢
    • 2017-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多