Rails admin with witchcraft
I am trying to install the Rails Admin Gem using Sorcery for authentication instead of Devise.
The Rails administrator provides a binding that you can use to attach your own authentication method. Here's an example they provide in their docs (with the help of an overseer):
config.authenticate_with do
warden.authenticate! :scope => :admin
end
config.current_user_method { current_admin }
I guess inside the block I need to reference before_filter
which Sorcery is using to authenticate users, which will be require_login
.
However, when I try to do this and I try to visit /admin
on logout, I get a routing error:
No route matches {:action=>"new", :controller=>"sessions"}
This is probably because I am being redirected in the engine and not in the main application.
How can I set this up correctly?
source to share
# config/initializers/rails_admin.rb
RailsAdmin.config do |config|
config.authenticate_with do
# Use sorcery 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
source to share