我正在尝试通过Pundit为我的Proposal课程添加授权。
我已经设置了所有建议等,但我也有几个州有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并运行了发电机。
答案 0 :(得分:0)
我对你所指的aasm_gem一无所知,但从你的描述来看,这样的事情会起作用(我正在编造published?
和draft?
方法,因为我不知道您正在处理的实际API
def show?
return true if record.published?
return true if record.draft? && user.id == record.user_id
false
end