Rails Background Jobs with ActiveJob and Sidekiq

Background jobs improve performance by offloading time-consuming tasks like sending emails. This snippet uses ActiveJob with Sidekiq to send a welcome email asynchronously. The SendWelcomeEmailJob finds the user and triggers the mailer, while the User

JavaScript Debounce Function to Optimize Event Handling

Debouncing is essential for optimizing performance when handling frequent events like scrolling, resizing, or input typing. This snippet defines a debounce function in a separate file for modularity, allowing easy reuse across projects. The resizing.j

Rails ActiveStorage: Attach and Display Images Easily

This snippet enables a User model to attach an avatar image with just has_one_attached :avatar. The view logic checks if an avatar exists and displays it using image_tag. This approach avoids complex file storage logic, letting Rails handle uploads se

Using Rails Callbacks to Auto-Generate a Unique Slug

Slugs are essential for SEO-friendly URLs and user-friendly navigation, and this snippet ensures each article automatically generates a unique slug based on its title. Using the before_create callback, we transform the title into a URL-safe format usi

Rails Enum for Clean and Readable Status Management

Managing statuses in a Rails model can become messy with hardcoded values, but enums provide a clean and readable way to handle them. This snippet shows how to define an enum in an Order model, making it easy to reference statuses with descriptive sym

Ruby on Rails Concern for Soft Deletable Records Without Losing Data

Trix editor with copy-paste Youtube embeds in Ruby on Rails, htmx and hyperscript

Add product to cart in Shopify with Liquid, htmx and hyperscript

Fetching notifications on click while showing pulsating placeholders with htmx and hyperscript on Rails

Post like / unlike with htmx on Rails - partial replacement, server-side rendering

Authorization concerns for models and controllers in Ruby on Rails

Accepting nested attributes in Ruby on Rails