ruby-on-rails

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

Search users as you type in Ruby on Rails with htmx

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

Accepting nested attributes in Ruby on Rails

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

Concern class with model dependent variations

by jarenas

Authorization concerns for models and controllers in Ruby on Rails

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

Rails Trackable Concern: Automatically Set Created By

The Trackable concern automatically assigns the created_by field when a record is created, using Current.user. This keeps model logic clean while ensuring proper tracking of record ownership. The Post model includes Trackable, to get this functionalit

Rails Callback: Automatically Normalize Usernames Before Save

This snippet ensures usernames are consistently formatted by automatically trimming spaces and converting them to lowercase before saving. The before_save callback in the User model prevents duplicates caused by case differences. The UsersController h

Detecting and storing user's timezone in Ruby on Rails automatically

This snippet automatically detects and stores a user's timezone by capturing it in JavaScript and saving it in a cookie. On every request, Rails reads this value and updates the user’s timezone in the database if needed. The local_time method then all

Ruby on Rails custom validator to validate HEX color format

This snippet defines a custom validator for hex color codes, ensuring that values follow the correct #RGB or #RRGGBB format. By using ActiveModel::EachValidator, the validation logic remains reusable across multiple models. This approach keeps models