我目前正在嘗試將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