Last active
December 16, 2024 13:26
-
-
Save flyingmate/12e60326a75d8121f634969230659b1e to your computer and use it in GitHub Desktop.
Here's a simple setup guide for integrating Active Admin 4, Rails 8, and Tailwind CSS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- views/active_admin/_html_head.html.erb --> | |
<%= stylesheet_link_tag :app %> | |
<meta name="viewport" content="width=device-width,initial-scale=1"> | |
<%= csrf_meta_tags %> | |
<%= csp_meta_tag %> | |
<% # On page load or when changing themes, best to add inline in `head` to avoid FOUC %> | |
<%= javascript_tag nonce: true do %> | |
if (localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) { | |
document.documentElement.classList.add('dark') | |
} else { | |
document.documentElement.classList.remove('dark') | |
} | |
<% end %> | |
<%= javascript_importmap_tags "active_admin", importmap: ActiveAdmin.importmap %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// config/tailwind.config.js | |
const defaultTheme = require('tailwindcss/defaultTheme') | |
const execSync = require('child_process').execSync; | |
const activeAdminPath = execSync('bundle show activeadmin', { encoding: 'utf-8' }).trim(); | |
module.exports = { | |
content: [ | |
'./public/*.html', | |
'./app/helpers/**/*.rb', | |
'./app/javascript/**/*.js', | |
'./app/views/**/*.{erb,haml,html,slim}', | |
`${activeAdminPath}/vendor/javascript/flowbite.js`, | |
`${activeAdminPath}/plugin.js`, | |
`${activeAdminPath}/app/views/**/*.{arb,erb,html,rb}`, | |
'./app/admin/**/*.{arb,erb,html,rb}', | |
'./app/views/active_admin/**/*.{arb,erb,html,rb}', | |
'./app/views/admin/**/*.{arb,erb,html,rb}', | |
'./app/views/layouts/active_admin*.{erb,html}', | |
'./app/javascript/**/*.js' | |
], | |
theme: { | |
extend: { | |
fontFamily: { | |
sans: ['Inter var', ...defaultTheme.fontFamily.sans], | |
}, | |
}, | |
}, | |
darkMode: "selector", | |
plugins: [ | |
require('@tailwindcss/forms'), | |
require('@tailwindcss/typography'), | |
require('@tailwindcss/container-queries'), | |
require(`${activeAdminPath}/plugin`) | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# zsh | |
rails new app_name -c tailwind | |
cd app_name | |
bundle add activeadmin --version "~> 4.0.0.beta14" | |
rails g active_admin:install | |
rm tailwind-active_admin.config.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment