0
votes

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

1

1 Answers

2
votes

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