Enabling YJIT

Ruby's JIT compiler needs a YJIT-enabled build and explicit activation; Rails 7.2+ enables it after boot, usually making it active already.

What we know about PDFKit

PDF generation from Rails uses a WebKit-based wrapper around wkhtmltopdf, with print styling, headers, footers, and binary-version pitfalls.

Capistrano: creating a database dump if migrating

Create a database dump only when Capistrano will run Rails migrations, using conditional migration checks and a deploy hook.

bower-rails can rewrite your relative asset paths

Precompiled CSS breaks relative image and font URLs when asset paths change; bower-rails can rewrite url(...) references into ERB asset helpers before deployment.

Rails: Join model table migration template

create_join_table builds association tables without ids or timestamps, using foreign keys and optional unique indexes to prevent orphaned or duplicate join records.

Sentry Local Logging in Ruby

Local Sentry event logging helps debug error capture and background jobs without sending data to Sentry or affecting production metrics.

Rails: Using database default values for boolean attributes

Boolean fields in Rails are safer with database defaults and NOT NULL constraints; application-level fallbacks are brittle, especially for tri-state values and instance-dependent defaults.

makandra cards: A knowledge base on web development, RoR, and DevOps

Internal knowledge base with best practices for web development, Ruby on Rails, DevOps, and trainee programs, used by developers worldwide to find practical solutions and learning paths.

Rails: Integrating shoelace components

Web components from Shoelace can be integrated into a Rails app with webpack and Unpoly, offering an alternative setup to the official approach.

Carrierwave: How to attach files in tests

CarrierWave uploads in tests often fail with multipart and file-assignment errors; common Rails and RSpec patterns attach fixtures with Rack::Test::UploadedFile, file_fixture, or attach_file.

Solving "TypeError (nil can't be coerced into Integer)" in the Rails console / IRB

Rails console assignments can print TypeError (nil can't be coerced into Integer) even when they succeed. The bug affects IRB with --nomultiline and is fixed in reline 0.2.0.

Rails: Using require and permit for attributes

Stricter strong parameters raise missing and unpermitted attribute errors during development and tests, helping catch bad requests earlier while requiring environment-specific handling in production.

Rails: Your index actions probably want strict_loading

Strict loading in index actions catches N+1 queries when views touch unpreloaded associations, causing test failures instead of hidden database hits.

RSpec: How to write isolated specs with cookies

Cookie-dependent behavior in Rails specs is hard to test outside controller specs, especially signed and encrypted values. ActionDispatch::Cookies::CookieJar provides isolated access in request and helper specs.

ActiveRecord: Creating many records works faster in a transaction

Bulk inserts into one table can be much faster inside a transaction; Rails 6+ also offers insert_all for a single multi-row INSERT without validations.

A different testing approach with Minitest and Fixtures

Minitest and fixtures can speed up slow Rails test suites, especially where RSpec and FactoryBot add overhead. Minimal fixtures and explicit assertions keep tests maintainable.

Databases don't order rows unless you tell them so

Database tables have no inherent row order; pagination with LIMIT needs a unique ORDER BY, and Rails first/last default to id.

Rails migration: Changing a column type without losing the content

Rails migrations can change column types without dropping data by using custom SQL casting, but rollback may fail when values cannot be converted.

Rails: Report CSP Violations to Sentry

CSP violations can be sent to Sentry for monitoring, but browser extensions and high-traffic sites may generate noisy reports and filtering remains limited.

WYSIWYG with Action Text

Rails 6 Action Text provides a built-in WYSIWYG editor for rich text fields, with Trix hooks for custom toolbar buttons and attachment handling.

Use CSS "text-overflow" to truncate long texts

Single-line text can overflow its container in Rails views; text-overflow: ellipsis and white-space: nowrap produce cleaner truncation in supported browsers.

Local development with SSL and Puma

Local HTTPS for Puma development needs a trusted certificate and SSL binding so Rails runs on https://localhost:3000 without browser warnings.

Rails: Remove Blank Values from Collections

Rails collections often retain empty strings, nil, whitespace, empty arrays, hashes, and false values; compact_blank removes them from arrays and hashes in Rails 6.1+.

How to use Rails URL helpers in any Ruby class

Accessing Rails path helpers from plain Ruby classes can be awkward, and including all route helpers risks method clashes. Delegating url_helpers exposes only the needed path methods.