ActiveAdmin with devise integration

Set up active admin that is expected to be used with devise.
Icons/chart bar
Used 194 times
Created by
T TobiasBales

Usage

Run this command in your Rails app directory in the terminal:

rails app:template LOCATION="https://railsbytes.com/script/xjNsv5"
Template Source

Review the code before running this template on your machine.

gem 'activeadmin'
gem 'bcrypt'

Bundler.with_unbundled_env { run 'bundle install' }


rails_command "generate active_admin:install --use_webpacker"
rails_command "generate active_admin:webpacker"
rails_command "generate active_admin:resource user"
rails_command "db:migrate"

gsub_file 'app/models/admin_user.rb', ':validatable', ':validatable, :pwned_password'

inject_into_file 'app/models/admin_user.rb', after: 'class AdminUser < ApplicationRecord' do <<~RB

    validates :email, presence: true
  RB
end

migration = Dir.glob("db/migrate/*").find { |f| f.end_with?('create_active_admin_comments.rb') }
gsub_file migration, 't.string :namespace', 't.string :namespace, null: false'
gsub_file migration, ':body', ':body, null: false'

gsub_file 'db/seeds.rb', "'password'", "'#{`pwgen -n 20 -1`}'"

gsub_file 'app/admin/dashboard.rb', 'end # content', 'end'

gsub_file 'test/fixtures/admin_users.yml', 'one: {}' do <<~EOF
    one:
      email: [email protected]
  EOF
end

gsub_file 'test/fixtures/admin_users.yml', 'two: {}' do <<~EOF
    two:
      email: [email protected]
  EOF
end

gsub_file 'app/javascript/packs/active_admin.js', '../stylesheets/active_admin', '../stylesheets/active_admin.scss'
Comments

Sign up or Login to leave a comment.