これがコントローラー全体に表示されます。
if not session[:admin]
flash[:notice] = "You don't have the rights to do #{:action}."
redirect_to :action=>:index
return
end
そしてその兄弟:
if not session[:user] and not session[:admin]
flash[:notice] = "You don't have the rights to do #{:action}."
redirect_to :action=>:index
return
end
メソッドで使用する場合は、これをすべて宣言行に減らしたいと思います。
def action_which_requires_rights
require_rights :admin
#or:
#:require_rights :user_or_admin
end
明らかに、require_rights が失敗した場合、残りのメソッドを実行したくありません。これを行う方法があったことを誓いますが、それについて読んだ場所が見つかりません。私はこれを想像していますか?