我目前正在尝试将inherited_resources和权限集成到我的Rails应用程序中。集成inherited_resources和权限
对于检查基于资源执行控制器操作的能力,我有点卡住了。此代码是作为一个例子给出权威:
def edit
@llama = Llama.find(params[:id])
authorize_action_for(@llama) # Check to see if you're allowed to edit this llama. failure == SecurityViolation
end
def update
@llama = Llama.find(params[:id])
authorize_action_for(@llama) # Check to see if you're allowed to edit this llama.
@llama.attributes = params[:llama] # Don't save the attributes before authorizing
authorize_action_for(@llama) # Check again, to see if the changes are allowed.
if @llama.save?
# etc
end
由于inherited_resources的发现者被抽离,我认为这会是不错的也钉在authorise_action_for
检查到这些抽象的发现者。
注意权限的更新情况下的双重检查(可能是创建)。
请注意,你应该在这里发布答案的重要部分,在这个网站上,或者被删除您的帖子风险[参见常见问题解答它提到的答案几乎不超过链接。](http://stackoverflow.com/faq#deletion)如果您愿意,您可能仍然包含链接,但仅作为“参考”。答案应该独立,不需要链接。 – Taryn 2013-07-19 11:32:48