基本提案的 Pundit 授权 Class
Pundit Authorization for Basic Proposal Class
我正在尝试通过 Pundit 为我的提案添加授权 class。
我已经设置了所有提案的创建等,但我还有几个 aasm_gem 的提案状态。起草、出版和关闭。
我只希望拥有该提案的用户能够查看起草的提案。然后在发布时任何用户都应该能够查看该提案。
我将如何着手制定实现这一目标的 Pundit 政策?我无法从文档中完全理解。如果我能看到一个例子,我应该能够弄明白。
我目前在展示页面上用这个在状态之间转换:
<%= button_to 'Publish Proposal', proposals_publish_path(@proposal), method: :put, class:"pull-right btn btn-primary btn-lg", style:"color:white; border: 0px; margin-top:15px;" %>
我已经安装了 Pundit 和 运行 生成器。
我对你提到的aasm_gem一无所知,但根据你的描述,类似这样的东西会起作用(我正在编造published?
和 draft?
方法,因为我不知道你正在处理的实际 API)
def show?
return true if record.published?
return true if record.draft? && user.id == record.user_id
false
end
我正在尝试通过 Pundit 为我的提案添加授权 class。
我已经设置了所有提案的创建等,但我还有几个 aasm_gem 的提案状态。起草、出版和关闭。
我只希望拥有该提案的用户能够查看起草的提案。然后在发布时任何用户都应该能够查看该提案。
我将如何着手制定实现这一目标的 Pundit 政策?我无法从文档中完全理解。如果我能看到一个例子,我应该能够弄明白。
我目前在展示页面上用这个在状态之间转换:
<%= button_to 'Publish Proposal', proposals_publish_path(@proposal), method: :put, class:"pull-right btn btn-primary btn-lg", style:"color:white; border: 0px; margin-top:15px;" %>
我已经安装了 Pundit 和 运行 生成器。
我对你提到的aasm_gem一无所知,但根据你的描述,类似这样的东西会起作用(我正在编造published?
和 draft?
方法,因为我不知道你正在处理的实际 API)
def show?
return true if record.published?
return true if record.draft? && user.id == record.user_id
false
end