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

Build image, run container, connect to already running container and investigate

Move one record to trash using Rails concern

Useful concern to allow you to move records to the trash without deleting the record. Please, write a migration to add the column trashed_at to your table

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

Export mysql database when facing GTID_PURGED error

I was facing ERROR 3546 (HY000): @@GLOBAL.GTID_PURGED cannot be changed when restoring previously exported mysql database. The solution is to add --set-gtid-purged=OFF setting when exporting.

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

Concern class with model dependent variations

by jarenas