1
質量分配模型的所有權,我有兩個型號,像這樣一個嵌套的路線:驗證使用淺路線
resources :books do
resources :chapters, :shallow => true
end
,並希望能有一本書的章節的嵌套形式。
如何檢查每個質量分配的章節書是否屬於用戶。
我試圖將它添加到控制器像這樣
class ChaptersController < ApplicationController
before_filter :check_ownership_of_chapters_book
def check_ownership_of_chapters_book
if Book.find(params[:book_id]).author != current_user
flash[:error] = "You are not the author of the book you are adding the chapter to"
redirect_to root_url
end
end
...
它產生這個錯誤
爲本書的ID「沒有ID找不到書」沒有通過param。
但我想,也許我應該做的模型檢查(檢查該章插入本書屬於CURRENT_USER)