A mountable blog engine for any Rails application with enhanced styling for Tailwind CSS and DaisyUI. Originally designed for Lightning Rails but works perfectly with any Rails app!
Lightning Blog is designed to work with:
- β Lightning Rails (enhanced experience with Tailwind + DaisyUI)
- β Standard Rails apps with Tailwind CSS (great styling)
- β Any Rails application (beautiful fallback styles)
- π Full Blog Functionality: Create, manage, and display blog posts
- π Categories: Organize posts by categories
- π Search: Full-text search across posts
- π± Responsive Design: Mobile-friendly interface that works everywhere
- πΌοΈ Image Support: Featured images for posts using Active Storage
- π Analytics: View counts and post statistics
- π¨ Smart Styling: Enhanced UI with Tailwind/DaisyUI, graceful fallbacks without
- β‘ Lightning Fast: Optimized for performance
- π Dark Mode: Automatic dark mode support
Get the full experience with Tailwind CSS and DaisyUI components perfectly integrated with your Lightning Rails application.
Enhanced styling with Tailwind classes. Add DaisyUI following the official Rails guide for the complete component library.
Beautiful fallback styles that match modern design principles. No additional dependencies required!
Add this line to your Rails application's Gemfile:
gem 'lightning_blog', path: '/path/to/lightning_blog'
Or if you're using it from a Git repository:
gem 'lightning_blog', git: 'https://github.com/LightningRails/lightning_blog.git'
And then execute:
$ bundle install
Use the automated installer:
$ rails generate lightning_blog:install
This will:
- β Copy migrations to your app
- β
Mount the blog engine at
/blog
- β Detect your Tailwind/DaisyUI setup automatically
- β Create a configuration file
- β Provide setup guidance based on your environment
- Copy and run migrations:
$ rails lightning_blog:install:migrations
$ rails db:migrate
- Mount the engine in your
config/routes.rb
:
Rails.application.routes.draw do
mount LightningBlog::Engine => "/blog"
# Your other routes...
end
- Seed sample data (optional, for development):
$ rails db:seed
# The gem automatically detects Lightning Rails and uses enhanced styling
# No additional configuration needed! π
Following the official DaisyUI Rails guide, you have 3 options:
# Install DaisyUI via NPM
npm install daisyui@latest
Add to your app/assets/tailwind/application.css
:
@import "tailwindcss" source(none);
@source "../../../public/*.html";
@source "../../../app/helpers/**/*.rb";
@source "../../../app/javascript/**/*.js";
@source "../../../app/views/**/*";
@plugin "daisyui";
# Download DaisyUI files
curl -sLo app/assets/tailwind/daisyui.js https://github.com/saadeghi/daisyui/releases/latest/download/daisyui.js
Add to your app/assets/tailwind/application.css
:
@import "tailwindcss" source(none);
@source "../../../public/*.html";
@source "../../../app/helpers/**/*.rb";
@source "../../../app/javascript/**/*.js";
@source "../../../app/views/**/*";
@plugin "./daisyui.js";
Add to your app/assets/tailwind/application.css
:
@import "tailwindcss" source(none);
@source "../../../public/*.html";
@source "../../../app/helpers/**/*.rb";
@source "../../../app/javascript/**/*.js";
@source "../../../app/views/**/*";
@import "https://cdn.jsdelivr.net/npm/daisyui@5";
# The gem includes beautiful fallback styles - works out of the box!
# Optionally add Tailwind CSS + DaisyUI for enhanced experience:
# https://daisyui.com/docs/install/rails/
Once mounted, your blog will be available at:
- Blog Index:
/blog
- Lists all published posts - Individual Posts:
/blog/post-slug
- Shows a specific post - Categories:
/blog/categories
- Lists all categories - Category Posts:
/blog/category/category-slug
- Posts by category - Search:
/blog?search=query
- Search posts
Lightning Blog provides models for managing your blog content:
# Create a new category
category = LightningBlog::Category.create!(
name: "Technology",
slug: "technology",
description: "Posts about technology"
)
# Create a new post
post = LightningBlog::Post.create!(
title: "My First Blog Post",
slug: "my-first-blog-post",
content: "This is the content of my blog post...",
excerpt: "A brief excerpt...",
category: category,
published: true
)
Lightning Blog supports Cloudinary for professional image hosting and delivery. Cloudinary provides automatic image optimization, transformations, and CDN delivery for better performance.
- Add Cloudinary to your Gemfile:
gem 'cloudinary'
- Install the gem:
bundle install
- Configure Active Storage to use Cloudinary in your
config/storage.yml
:
cloudinary:
service: Cloudinary
# Your credentials will be loaded from CLOUDINARY_URL env variable
# or set them here directly:
# cloud_name: your_cloud_name
# api_key: your_api_key
# api_secret: your_api_secret
- Set Cloudinary as your Active Storage service in the appropriate environment file:
# config/environments/production.rb
config.active_storage.variant_processor = :image_processing
config.active_storage.service = :cloudinary
# config/environments/development.rb (optional)
config.active_storage.service = :cloudinary
- Get your Cloudinary credentials:
- Sign up at cloudinary.com
- Copy your
CLOUDINARY_URL
from the dashboard - Add it to your environment variables or
.env
file:
CLOUDINARY_URL=cloudinary://api_key:api_secret@cloud_name
- β Automatic optimization - Images served in optimal format and size
- β Global CDN delivery - Fast loading worldwide
- β Real-time transformations - Resize, crop, format images on-the-fly
- β Responsive images - Automatic device-appropriate sizing
- β SEO benefits - Faster page loads improve search rankings
Once configured, Lightning Blog will automatically use Cloudinary for:
- Featured images on blog posts
- Image attachments in post content
- Category images (if you add them)
- User avatars (if you extend the models)
# Example: Creating a post with featured image
post = LightningBlog::Post.create!(
title: "My Post with Image",
content: "Post content...",
category: category,
published: true
)
# Attach image from file upload
post.featured_image.attach(params[:featured_image])
# Or attach from URL
post.featured_image.attach(
io: URI.open('https://example.com/image.jpg'),
filename: 'featured-image.jpg'
)
Lightning Blog views are optimized for Cloudinary transformations:
<!-- Automatic responsive images -->
<%= image_tag post.featured_image.variant(resize: "800x600"),
class: "responsive-image",
alt: post.title %>
<!-- Multiple sizes for different devices -->
<%= image_tag post.featured_image,
sizes: "100vw",
srcset: [
"#{url_for(post.featured_image.variant(resize: '400x'))} 400w",
"#{url_for(post.featured_image.variant(resize: '800x'))} 800w",
"#{url_for(post.featured_image.variant(resize: '1200x'))} 1200w"
].join(', ') %>
Note: Lightning Blog works perfectly without Cloudinary using Rails' default Active Storage with local files. Cloudinary is recommended for production applications requiring professional image handling.
The gem uses Tailwind classes and DaisyUI components. You can customize themes following the Lightning Rails theming guide:
/* Custom theme in your application.css */
[data-theme="lightning-blog"]{
--color-primary: #F9462F;
--color-primary-content: #ffffff;
--color-secondary: #000000;
--color-base-100: #ffffff;
/* ... other DaisyUI variables */
}
Override styles in your application.css
:
/* Override Lightning Blog styles */
body:not(.tailwind-loaded) .card {
background-color: your-color;
/* Your custom styles */
}
Override any view by creating the corresponding file in your application:
app/views/lightning_blog/
βββ posts/
β βββ index.html.erb
β βββ show.html.erb
βββ categories/
β βββ index.html.erb
β βββ show.html.erb
βββ layouts/
βββ application.html.erb
# config/routes.rb
Rails.application.routes.draw do
# Mount at root path
mount LightningBlog::Engine => "/"
# Or mount at custom path
mount LightningBlog::Engine => "/articles"
# Add custom routes
get "/latest-posts", to: "lightning_blog/posts#index"
end
# Works seamlessly - enhanced styling automatically applied!
# Perfect integration with your Lightning Rails design system
# app/controllers/lightning_blog/application_controller.rb
module LightningBlog
class ApplicationController < ::ApplicationController
before_action :authenticate_user!, if: :admin_required?
private
def admin_required?
params[:action].in?(['new', 'create', 'edit', 'update', 'destroy'])
end
end
end
# Track blog performance
<% if params[:controller] == 'lightning_blog/posts' && params[:action] == 'show' %>
gtag('event', 'page_view', {
page_title: '<%= @post.title %>',
page_location: '<%= request.url %>'
});
<% end %>
LightningBlog::Post.published # Published posts only
LightningBlog::Post.recent # Ordered by creation date
LightningBlog::Post.by_category(cat) # Posts in specific category
LightningBlog::Post.search("query") # Search posts
post = LightningBlog::Post.first
post.reading_time # Estimated reading time
post.increment_views! # Increment view count
post.published? # Check if published
LightningBlog::Category.with_published_posts # Categories with published posts
category = LightningBlog::Category.first
category.posts.published # Published posts in category
# Run all tests
$ bundle exec rspec
# Build the gem
$ gem build lightning_blog.gemspec
Bug reports and pull requests are welcome on GitHub at https://github.com/LightningRails/lightning_blog.
A: Yes! Lightning Blog works with any Rails application (Rails 7.0+). It includes fallback styles for apps without Tailwind.
A: No, but it's recommended for the best experience. The gem includes beautiful fallback styles for standard Rails apps.
A: Follow the official DaisyUI Rails installation guide - our installer will detect your setup automatically.
A: Absolutely! The gem's styles are designed to coexist with other CSS frameworks.
A: Create admin controllers in your main app to manage Lightning Blog models, or integrate with existing admin panels.
Rails Version | Ruby Version | Tailwind | DaisyUI | Status |
---|---|---|---|---|
7.0+ | 3.0+ | β | β (NPM Plugin) | β Full Support |
7.0+ | 3.0+ | β | β (Downloaded JS) | β Full Support |
7.0+ | 3.0+ | β | β (CDN Import) | β Full Support |
7.0+ | 3.0+ | β | β | β Enhanced Styling |
7.0+ | 3.0+ | β | β | β Fallback Styles |
- π DaisyUI Rails Installation Guide
- π¨ DaisyUI Components
- β‘ Lightning Rails Documentation
- π― Lightning Rails Theming Guide
The gem is available as open source under the terms of the MIT License.
- β Universal Rails compatibility
- β Official DaisyUI Rails integration (all 3 methods)
- β Automatic setup detection
- β Fallback styles for standard Rails
- β Search functionality
- β Category management
- β Responsive design
- β SEO optimization
For support, please:
- Check the official DaisyUI Rails guide
- Review the documentation above
- Search existing issues on GitHub
- Create a new issue with detailed information
Built with β€οΈ for the Rails community. Optimized for Lightning Rails, perfect for everyone! β‘