2012-03-22 17 views
3

私はRails Admin Gemをインストールして、SorceryをDeviseの代わりに認証に使用しようとしています。Rails admin with Sorcery

Rails管理者は、独自の認証方法を添付するためのフックを提供します。 Hereは、彼らが彼らのドキュメント(監視員を使用して)で提供例です。

config.authenticate_with do 
    warden.authenticate! :scope => :admin 
end 
config.current_user_method { current_admin } 

私はブロック内で、私はrequire_loginだろうソーサリーは、ユーザーを認証するために使用するbefore_filterを、参照する必要が推測しています。私はそれを試してみて、私は/adminを訪問しようとすると、

ただし、ログアウトしたときに、私は、ルーティングエラーが表示されます。私は、エンジン内ではなく、メインのアプリにリダイレクトされていますので、

No route matches {:action=>"new", :controller=>"sessions"} 

これはおそらく起こります。

これを正しく設定するにはどうすればよいですか?あなたはCancancan宝石とソーサリーを使用する場合は

答えて

6
# config/initializers/rails_admin.rb 
RailsAdmin.config do |config| 
    config.authenticate_with do 
    # Use sorcery's before filter to auth users 
    require_login 
    end 
end 

# app/controllers/application_controller.rb 
class ApplicationController 
    # Overwrite the method sorcery calls when it 
    # detects a non-authenticated request. 
    def not_authenticated 
    # Make sure that we reference the route from the main app. 
    redirect_to main_app.login_path 
    end 
end 
0

、また、あなたのconfig/initializers/rails_admin.rbファイルにconfig.current_user_method(&:current_user)を追加する必要があります。または、エラーが発生します:You are not authorizedを。