Banner System Documentation
October 9, 2025 · View on GitHub
Overview
The banner system allows you to display site-wide banners at the top of each page that can be managed through ComfyCMS admin interface. Banners can be closed by users and their state is remembered via cookies.
Features
- Site-wide display: Banners appear on all pages
- Cookie-based persistence: Once closed, banners stay hidden until a new banner is created
- Rich text content: Banners use ComfyCMS rich text editor for content formatting
- Optional titles: Banner titles are optional for more flexible design
- Admin management: Full CRUD interface in ComfyCMS admin
- Active/inactive states: Control banner visibility
Admin Interface
Access the banner management at /admin/banners in the ComfyCMS admin interface.
Banner Fields
- Title: Banner title (optional, max 100 characters)
- Content: Rich text content for the banner body (uses ComfyCMS rich text editor)
- Active: Whether the banner is currently displayed
Banner Management
- Create: Click "New Banner" to create a new banner
- Edit: Click "Edit" on any banner to modify it
- Delete: Click "Delete" to remove a banner
- Activate/Deactivate: Toggle the "Active" checkbox to show/hide banners
Technical Implementation
Models
Banner: Main model storing banner datacurrent_banner: Helper method to get the active bannerbanner_visible?: Helper method to check if banner should be displayed
Views
app/views/layouts/partials/_banner.html.erb: Banner display template- Admin views in
app/views/admin/banners/
JavaScript
app/javascript/components/banner/Banner.vue: Vue component handling banner display and navigation- Handles single and multiple banner scenarios
- Sets appropriate cookies (single banner ID or signature for multiple)
- Provides smooth close animation and left/right navigation
CSS
app/assets/stylesheets/banner.scss: Banner styling- Responsive design
- Multiple color variants
Usage Examples
Creating a Simple Banner
- Go to
/admin/banners - Click "New Banner"
- Fill in:
- Title: "Site Maintenance" (optional)
- Content: Use the rich text editor to format: "We will be performing maintenance on Sunday at 2 AM."
- Active: ✓
- Click "Create Banner"
Creating an Info Banner with Link
- Go to
/admin/banners - Click "New Banner"
- Fill in:
- Title: "New Feature Available" (optional)
- Content: Use the rich text editor to format: "Check out our new interactive map!"
- Active: ✓
- Click "Create Banner"
Creating a Banner Without Title
- Go to
/admin/banners - Click "New Banner"
- Fill in:
- Title: Leave blank
- Content: Use the rich text editor to format your message
- Active: ✓
- Click "Create Banner"
Cookie Behavior
- When a user closes a banner, a cookie is set with the banner ID
- The cookie expires after 1 year
- If a new banner is created, it will be shown even if the user previously closed a different banner
- The cookie is named
banner_closedand contains the banner ID
Customization
Modifying Banner Display
Edit app/views/layouts/partials/_banner.html.erb to change the banner structure.
JavaScript Customization
Modify app/javascript/components/banner/Banner.vue to change close behavior or add new functionality. The component follows Vue.js patterns and can be extended with additional features like auto-rotation, keyboard navigation, etc.
Database Schema
CREATE TABLE banners (
id SERIAL PRIMARY KEY,
title VARCHAR(255),
content TEXT NOT NULL,
is_active BOOLEAN DEFAULT true NOT NULL,
created_at TIMESTAMP NOT NULL,
updated_at TIMESTAMP NOT NULL
);
Migration
To set up the banner system:
- Run the migration:
rails db:migrate - Seed sample data:
rails db:seed - Access admin at
/admin/banners
Troubleshooting
Banner Not Showing
- Check if a banner exists and is active
- Verify the banner is not closed via cookie
- Check browser console for JavaScript errors
Admin Access Issues
- Ensure you're logged into ComfyCMS admin
- Check that routes are properly configured
- Verify controller permissions
Styling Issues
- Check that
banner.scssis imported inapplication.scss - Verify CSS classes are correctly applied
- Check for CSS conflicts