1
votes

I have three users - investor, sme and admin. I have the following code in my application_controller.rb

class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception
  devise_group :person, contains: [:investor,:sme]

  before_action :authenticate_person!

  before_action do |controller|
    redirect_to root_path if devise_controller? && person_signed_in?
  end
end

Now the problem is when I log into the admin panel I get redirected back to the investor signin page. Here's the server log

Started GET "/admin" for 127.0.0.1 at 2015-05-22 22:40:14 +0530
Processing by Admin::DashboardController#index as HTML
Completed 401 Unauthorized in 4ms


Started GET "/investors/sign_in" for 127.0.0.1 at 2015-05-22 22:40:14 +0530
Processing by Investors::SessionsController#new as HTML
Rendered investors/shared/_links.html.erb (4.0ms)
Rendered investors/sessions/new.html.haml within layouts/application (48.0ms)
Completed 200 OK in 2537ms (Views: 2532.5ms | ActiveRecord: 0.0ms)

Regardless of whether the authentication succeeds or fails, I'm redirected to the investor signin page.
Also, when I login as an investor or sme, I'm able to access the admin pages. Activeadmin is clearly confusing my normal users with admin user. Here's my config/initializers/active_admin.rb file

ActiveAdmin.setup do |config|
  config.authentication_method = :authenticate_admin_user!
  config.current_user_method = :current_admin_user
  config.logout_link_path = :destroy_admin_user_session_path
end

I tried adding config.skip_before_action :authenticate_person! to my active_admin.rb file, thinking that the before_action :authenticate_person! in my application_controller may be causing the problem, but it throws an error saying undefined method devise_group for application controller.

1

1 Answers

2
votes

I figured it..I had to add the following code in my app/admin/dashboard.rb file

controller do
  skip_before_filter :authenticate_person!
end

had tried adding config.skip_before_filter :authenticate_person! in config/initializers/active_admin.rb but it was causing the error undefined method devise_group for application controller. Even though this works, I get a redirection loop when I try to access the /admin/login page while being logged in as a normal user.
Hope this helps whoever is stuck