How to make an active admin use the user table already used in development and cancan?

I am using a device to authenticate and cancan to authorize in my application. The app did a great job with them. But now I wanted to use an active admin to manage all the users that are already in my application that are used in development and cancan. Active admin creates its own admin_users table for users. how can I get active_admin to use the users and roles table that was previously used? thanks for the help.

+3


source to share


3 answers


If you have already created a table users

, then you should skip creating this table.

Duration:

rails generate active_admin:install --skip-users

      

And don't forget to run:

bundle exec rake db:migrate

      

Try changing the authentication method in the file config/initializers/active_admin.rb

. Also make sure you have a method created current_admin_user

, if you don't, you can just change it to the default ( current_user

).

You will need to change the http method used in the logout link to :delete

.



config.logout_link_method = :delete

      

And the route route to the logout action.

config.logout_link_path = :destroy_user_session_path

      

To understand the authentication method better, I am pasting my app/controllers/application_controller.rb

respective code:

class ApplicationController < ActionController::Base
  protect_from_forgery

  #
  # redirect registered users to a profile page
  # of to the admin dashboard if the user is an administrator
  #
  def after_sign_in_path_for(resource)
    resource.role == 'admin' ? admin_dashboard_path : user_path(resource)
  end

  def authenticate_admin_user!
    raise SecurityError unless current_user.try(:role) == 'admin'
  end

  rescue_from SecurityError do |exception|
    redirect_to root_path
  end
end

      

Hope this helps you and maybe someone else.

+7


source


By default, a new Devise user / model will be created called AdminUser. To change the name of a user's class, simply pass the class as the last argument:

rails generate active_admin:install User

      



http://activeadmin.info/docs/0-installation.html

http://activeadmin.info/docs/1-general-configuration.html#authentication

+4


source


if you have already run the activeadmin .... commands you can use the existing user table by changing the admin_user for the user in active_admin.rb in the initializer and define the admin capability in the Cancan model. Also you have to do something like admin authorization for DSL authorization

0


source







All Articles