0

This may be something simple but I need a clarity please. I already have Active rails MODEL Profile(representing Users) so devise is already using the MODEL Profile I know active admin integrates with devise but how can I generate active_admin to use my existing Profile so I can manage all Profiles(users) at back end?

Profile.rb

class Profile < ApplicationRecord
  is_impressionable
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable, :confirmable


            has_many :ads, dependent: :destroy 
end

routes.rb

Rails.application.routes.draw do
  devise_for :admin_users, ActiveAdmin::Devise.config
  ActiveAdmin.routes(self)
  devise_for :profiles
  resources :profiles
  resources :ad

  root 'motors#index'
end

I have also read the active admin documentation which states

If you want to use an existing user class, provide it as an argument:

rails g active_admin:install User

therefore I tried: rails g active_admin:install Profile but didn't work

Charlie
  • 236
  • 2
  • 13

1 Answers1

2

In the Devise docummentation:

rails generate devise MODEL

means that you must have an active rails model called MODEL (Profile, in your case). Since you already have the Users model, then you have to use that, or if you must use Profile, then (re)create a Model (or Scaffold, as the case may be) with the same name.

I would not advise you to try to rename the Users model to Profile as it came with other pieces of baggage that you may miss in the renaming process (read more here and here), which could cause conflicts later in your development. Really, if it is a fairly new app just destroy the model (or scaffold) and create another with the desired name.

When you have decided on the model to use, then

rails generate active_admin:resource MyModel

as per the active_admin documentation

Chidozie Nnachor
  • 872
  • 10
  • 21
  • 1
    thanks for the answer, I already have Active rails MODEL Profile not User so devise is already using the MODEL Profile – Charlie Jul 07 '18 at 12:12
  • Edit your question. Add the code from (1) profile.rb (2)active_admin (3) routes – Chidozie Nnachor Jul 07 '18 at 17:17
  • question has been modified – Charlie Jul 07 '18 at 19:20
  • 1
    I think you're trying to install active_admin for TWO models which does not make sense. You can have devise for two models, but not admin. What you can do is create different admin ROLES in the same model. So I suggest you destroy the active_admin for Users and run again for Profile: rails destroy active_admin:install rails destroy active_admin:resource user – Chidozie Nnachor Jul 07 '18 at 20:22
  • 1
    Thanks for your help, issue has now been resolved, I didn't know active_admin users are completely separated from the rails regular users – Charlie Jul 07 '18 at 20:44