In my App I have successfully installed Devise and it works perfectly nice. Then I have first time installed Active Admin for Admin panel and have set path. Now when I try to login in Active Admin localhost:3000/admin/login it redirect me to Devise's login page. I know there may be silly mistake but not aware how to solve this issue??
app/config/initializers/active_admin.rb
ActiveAdmin.setup do |config| #I have removed comments
config.site_title = "Shopaholic"
config.authentication_method = :authenticate_admin_user!
config.current_user_method = :current_admin_user
config.logout_link_path = :destroy_admin_user_session_path
config.batch_actions = true
end
app/config/initializers/devise.rb
Devise.setup do |config|
config.secret_key = '28c01a5ccf820bb594d2b6421becfa6487df79dad52a57d49cf61f802ea00c7364215f43cdf87463503e658da69e182f8c35d668577f975fea2bdee736a5d20a'
config.mailer_sender = '[email protected]'
require 'devise/orm/active_record'
config.authentication_keys = [ :email ]
config.case_insensitive_keys = [ :email ]
config.strip_whitespace_keys = [ :email ]
config.skip_session_storage = [:http_auth]
config.stretches = Rails.env.test? ? 1 : 10
config.remember_for = 2.weeks
config.password_length = 8..128
config.reset_password_within = 6.hours
config.default_scope = :users
config.sign_out_via = :delete
end
routes.rb
Shopaholic::Application.routes.draw do
root :to => "products#products_list"
#root to: "admin/dashboard#index"
devise_for :admin_users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)
devise_for :users
ActiveAdmin.routes(self)
end
If you required any further information then let me know I will Update. Please help me to solve this issue.. Thanks in advance
in your
config/initializers/active_admin.rb
add the following to the bottom of the setup block
ActiveAdmin::BaseController.class_eval do
skip_before_filter :authenticate_user!
end
UPDATE: with Rails 5.0 and higher you'll want to add it like this:
config.skip_before_action :authenticate_user!
I think If you have this block in application_controller.rb then it will redirect you to Devise's login page:
def after_sign_in_path_for(resource)
users_path
end
To resolve this redirection use this block instead of above block:
def after_sign_in_path_for(resource)
if resource.is_a?(AdminUser)
admin_dashboard_path
else
users_path
end
end
And if you have still issue due to "before_action :authenticate_user!" this on application_controller.rb then as per @YodaTravis use this block in bottom of config/initializers/active_admin.rb
ActiveAdmin::BaseController.class_eval do
skip_before_filter :authenticate_user!
end
It will work for you!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With