Skip to content

Instantly share code, notes, and snippets.

@giuseb
Last active January 21, 2025 07:24
Show Gist options
  • Save giuseb/fc399e0196f5eb6d16007715835f7265 to your computer and use it in GitHub Desktop.
Save giuseb/fc399e0196f5eb6d16007715835f7265 to your computer and use it in GitHub Desktop.
ActiveAdmin 4 on Rails 8, nodeless.
# modified from @amkisko
# https://gist.github.com/amkisko/c704c1a6462d573dfa4820ae07d807a6ò
# Rails 8 defaults: sqlite3, propshaft, importmap
rails new aa4nodeless -c tailwind
cd aa4nodeless
bundle add devise
rails g devise:install
bundle add activeadmin --version=4.0.0.beta15
rails g active_admin:install
rails g active_admin:assets
rails db:migrate
rails g active_admin:views
mv tailwind-active_admin.config.js config/
echo "active_admin: bin/rails active_admin:watch" >> Procfile.dev
# edit config/tailwind-active_admin.config.js:
# - comment out line 2: // import activeAdminPlugin from...
# - inside plugins, replace activeAdminPlugin with require(`${activeAdminPath}\/plugin.js`)
# place active_admin.rake (below) in lib/tasks/
# add code below to config/initializers/active_admin.rb
# copied from @ryanckulp
# https://gist.github.com/ryanckulp/4872d0379b642421928b9d24d9c5d38c
namespace :active_admin do
COMMAND = [
Rails.root.join("bin/tailwindcss").to_s,
"-i", Rails.root.join("app/assets/stylesheets/active_admin.css").to_s,
"-o", Rails.root.join("app/assets/builds/active_admin.css").to_s,
"-c", Rails.root.join("config/tailwind-active_admin.config.js").to_s,
"-m" # minify
]
desc "Build Active Admin Tailwind stylesheets"
task build: :environment do
system(*COMMAND, exception: true)
end
desc "Watch Active Admin Tailwind stylesheets"
task watch: :environment do
command = COMMAND.push("--watch")
system(*command)
end
end
Rake::Task["assets:precompile"].enhance(["active_admin:build"])
Rake::Task["test:prepare"].enhance(["active_admin:build"]) if Rake::Task.task_defined?("test:prepare")
Rake::Task["spec:prepare"].enhance(["tailwindcss:build"]) if Rake::Task.task_defined?("spec:prepare")
Rake::Task["db:test:prepare"].enhance(["tailwindcss:build"]) if Rake::Task.task_defined?("db:test:prepare")
ActiveAdmin.importmap.draw do
pin "@rails/actioncable", to: "actioncable.esm.js", preload: true
pin "@rails/activestorage", to: "activestorage.esm.js", preload: true
pin "@hotwired/turbo-rails", to: "turbo.js", preload: true
pin "@hotwired/stimulus", to: "stimulus.js", preload: true
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true
pin "application", preload: true
pin_all_from "app/assets/javascripts/controllers", under: "controllers"
end
ActiveAdmin.setup do |config|
# all the rest of the initializer
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment