我希望能夠讓管理員屬性爲的用戶設置爲true來訪問rails_admin。因此,如果用戶將is_admin屬性設置爲true,則可以訪問rails_admin界面。使用管理員屬性驗證rails_admin
我已經檢查他們的文檔和所有我能找到的認證是在這裏:https://github.com/sferik/rails_admin/wiki/Authentication
請,你能不能幫我這樣做呢?
感謝
我希望能夠讓管理員屬性爲的用戶設置爲true來訪問rails_admin。因此,如果用戶將is_admin屬性設置爲true,則可以訪問rails_admin界面。使用管理員屬性驗證rails_admin
我已經檢查他們的文檔和所有我能找到的認證是在這裏:https://github.com/sferik/rails_admin/wiki/Authentication
請,你能不能幫我這樣做呢?
感謝
文檔已經解釋了,你必須做的:
在你rails_admin.rb初始化:
config.authenticate_with do
warden.authenticate! :scope => :admin
end
config.current_user_method { current_admin } # hook to your 'current_user' method
而用戶模式你生成current_admin方法:
def current_admin
current_user && current_user.is_admin
end
我認爲這應該工作。
從https://github.com/sferik/rails_admin/wiki/Authorization
config.authorize_with do
redirect_to main_app.root_path unless current_user.is_admin?
end
Mattherick請問這個warden.authenticate! :scope =>:admin是什麼意思? – 2013-05-04 13:01:02
也許這回答你的問題:https://github.com/hassox/warden/wiki/Scopes。你可以配置你的rails_admin來使用warden認證。 – Mattherick 2013-05-04 13:13:26