所以我有3種類型的用戶:Rails的允許訪問一個頁面,而不會限制整個控制器
admin
moderator
regular user
我有一個控制器級系統這樣鎖定了主持人和管理頁面:
def authorize
unless User.find_by_id(session[:user_id]) and User.find_by_id(session[:user_id]).moderator == true
redirect_to login_url, :notice => "Please log in with a moderator account"
end
end
def authorize_admin
unless User.find_by_id(session[:user_id]) and User.find_by_id(session[:user_id]).admin == 1
redirect_to login_url, :notice => "Only admins can access the page you tried to access"
end
end
但我需要讓普通用戶訪問多個控制器的編輯頁面(當然還有更新操作)。但只是編輯和更新。
如果我做的:
before_filter :authorize, :except => :edit
那麼任何人(即使不登錄)訪問這些頁面。
我該如何去做類似的事情?
編輯
按蒂洛的建議下,我增加了以下的application_controller.erb文件:
def update_successful
skip_before_filter :authorize
end
爲了能夠服務於update_successful頁普通用戶編輯了一個條目後。不過,我得到這個錯誤:
undefined method `skip_before_filter' for #<HomeController:0x007ff782aeb6f0>
你目前如何使用這兩種方法?作爲'before_filter'? – Thilo 2012-04-19 15:23:10
是的,before_filter。 – kakubei 2012-04-19 15:23:59