我試圖讓permit
方法使用rails-authorization-plugin和authlogic上班,我一直運行到這個錯誤:Rails的授權插件出錯
當我嘗試:
class ApplicationController < ActionController::Base
...
before_filter permit 'admin'
...
我得到這個:
Authorization::CannotObtainUserObject in HomeController#index
Couldn't find #current_user or @user, and nothing appropriate found in hash
現在,我有我的current_user
方法設置,和它的作品,因爲我在我的應用程序使用它幾乎無處不在其他:
class ApplicationController < ActionController::Base
...
helper_method :current_user
private
def current_user_session
return @current_user_session if defined?(@current_user_session)
@current_user_session = UserSession.find
end
def current_user
return @current_user if defined?(@current_user)
@current_user = current_user_session && current_user_session.record
end
...
我也知道,我有我的數據庫中相應角色的用戶,因爲這種方法的工作原理:
def require_admin
unless current_user.is_admin? || current_user.is_root?
flash[:warning] = 'You are not an administrator and cannot access this page.'
redirect_to root_path
end
end
我可以做一切工作,如果我只是在用戶級檢查使用這樣的:
before_filter :require_admin, :only => 'index'
...但我不應該能夠與permit
和permit?
有效是一回事嗎?
任何幫助將不勝感激。如果您需要查看更多代碼,請告訴我,我很樂意發佈。谷歌真的沒有什麼能夠讓我們能夠讓這兩個系統相互合作。
我改變它像你所建議的(在全球範圍內),所以現在它只是讀'允許'管理員',但我仍然得到相同的錯誤。當我嘗試在每個操作級別上執行操作時,我會得到同樣的錯誤。 ?? – neezer 2009-10-10 14:51:22