Generating Secure One-Time Tokens Without Devise in Ruby on Rails

This snippet lets you generate secure, one-time-use tokens for password resets without Devise. It stores the token in the database, checks its validity, and clears it after use. The send_reset_link action sends the reset link, and the reset action ver

Ruby on Rails: Storing and Querying JSON Data in PostgreSQL

This snippet uses PostgreSQL’s JSONB column to store flexible metadata for orders, making it easy to store dynamic attributes without schema changes. The scopes allow efficient filtering using native SQL JSON functions. The update_metadata method enab

Shopify Liquid: Dynamic Free Shipping Bar

This snippet encourages larger cart values by dynamically showing how much more is needed for free shipping. The logic lives in free-shipping-bar.liquid, and it's rendered inside cart.liquid.

Custom product badges based on tags in Shopify Liquid

This setup separates the product badge logic into its own snippet product-badge.liquid, making it reusable across different sections like product listings and featured collections. The product-card.liquid section renders the badge alongside the produc

Automatically generate two-word slugs in Ruby on Rails

This snippet ensures every article gets a unique, readable slug based on its title, keeping it short and pronounceable. It grabs the first two words of the title and appends a 4-character random string to prevent duplicates. The before_validation call

Storing & querying IP addresses efficiently in Ruby on Rails

This snippet stores user IPs efficiently using the PostgreSQL inet type, which optimizes space and lookup speed. The from_same_network scope allows querying users within the same /24 subnet, useful for analytics or security checks. The update_ip metho