Skip to main content

10 docs tagged with "Ruby on Rails"

share my experience and my learning with Ruby on Rails codebase.

View all tags

Date.current vs Date.today in Ruby

Date.current and Date.today look interchangeable but behave differently when your server and app timezones don't match. Here's what each one actually does and when to use which

Pagination Gem vs .limit()

Use .limit() to restrict query size. When the frontend needs page count or navigation metadata, reach for a pagination gem like Pagy.

Rails.env and ENV

Rails.env checks which environment your app is running in. ENV reads OS-level variables. Here's how each works and when to use ENV.fetch over ENV[].

Safe Navigation Operator(&.)

Use &. to avoid NoMethodError when a value in a method chain might be nil. Here's how it works, when to use it, and how it differs from Rails's try.

Using store_accessor with JSONB Columns

store_accessor maps top-level keys in a JSONB column to model attributes, giving you validations, dirty tracking, and clean access without extra columns. Here's how it works and when to use it over dedicated columns.

Zeitwerk File Naming and Acronyms

Zeitwerk derives constant names from file names using camelize. When your class uses an acronym like AI, API, or CSV, you need to register it or Rails won't find it.