ruby-on-rails
ruby-on-rails
ruby
Integrating .ruby-version into your Rails Gemfile
Stop declaring your Ruby version twice: with a recent Bundler your Gemfile can read .ruby-version directly using ruby file: ".ruby-version". The one-line setup, the required Bundler upgrade, and how it keeps rbenv, RVM, or asdf and Rails in sync.
ruby
What is Turbo Frames in Rails?
Turbo Frames let Rails reload just a fragment of the page instead of the whole thing, with no custom JavaScript. What Turbo Frames are within Hotwire, a practical example of wrapping views in frames, and the responsiveness gains you get almost for free.
Latest
How to run Thruster and Kamal in Rails app
Thruster with Kamal in Rails: what 37signals' no-config proxy adds (HTTP/2, Let's Encrypt HTTPS, asset caching, X-Sendfile with compression), why it is still useful behind Traefik or Cloudflare, and how to integrate it into your app.
Introducing Threads, Parallelism, and Mutex in plain Ruby
Ruby threads explained in plain Ruby: how threads speed up I/O-heavy work, how race conditions corrupt shared resources, and how a Mutex protects critical sections, with runnable examples and no framework required.
Improve the performance of your Rails application through load testing
Load testing a Rails application step by step: why simulating peak traffic matters, how to set up a test machine and build complex scenarios, which performance metrics to measure, and how to turn the results into optimizations.
Implementing read and write databases in Rails
Rails read and write databases in practice: configure a primary and replica in database.yml, enable automatic connection switching, update ApplicationRecord, and handle the replication challenges that come with splitting the load.
How to create rake task and pass arguments
Creating rake tasks and passing arguments, four ways: the default bracket syntax, OptParse, raw ARGV, and Linux-style flags, plus namespaces and prerequisites for organizing tasks in a Rails app, each with a working example.
Adding Custom Inflections in Rails with Zeitwerk
Custom inflections in Rails with Zeitwerk: use ActiveSupport::Inflector in config/initializers/inflections.rb to register acronyms like API, CSV, or SSL, so autoloading maps file names to the capitalized class names you want.
Block attackers based on request URL in Ruby app
Blocking bots and attackers by request URL instead of IP: how the url_ban_list gem, born from three years of honeypot observations, recognizes malicious scan paths in your Ruby app and bans the clients requesting them.
How to work with JSONB column in pure Ruby on Rails
JSONB columns in Ruby on Rails without extra gems: use store_accessor to read and write keys like normal attributes, set sensible defaults, and validate required keys with a small module. Practical code you can drop into a PostgreSQL-backed Rails app.
Demystifying and writing own DSL in Ruby by examples - a practical guide
Ruby DSLs demystified by building three of them: a Minitest-like test framework, a Rails-style routes definition, and an RSpec-like spec syntax. See how blocks, instance_eval, and Ruby metaprogramming turn plain classes into a friendly mini-language.
What is ETag and how to use it in Rails for caching?
ETags let browsers skip downloading content that has not changed. What entity tags are in HTTP, then the Rails caching toolkit: stale?, fresh_when, expires_in, expires_now, public requests, and http_cache_forever, each shown with a concrete controller example.
How to run a command in the background and then kill it under bash terminal?
Run any command in the background in bash by appending &, check it with jobs, and stop it with kill -9 %. A short guide using a Rails server as the example, so long-running processes stop blocking your terminal while you keep working.
How to set domain and subdomain during the development stage for HTTP and HTTPS in Rails?
Need a real domain, subdomains, or HTTPS while developing a Rails app? nip.io gives any local IP a wildcard DNS name without touching your hosts file. How to configure Rails for it, enable local HTTPS, and quickly find your local IP address.
What is ACID?
ACID stands for Atomicity, Consistency, Isolation, and Durability: the four guarantees behind reliable database transactions. Each property explained with a concrete Rails example, like wrapping a money transfer in a transaction so it fully succeeds or rolls back.
What is instance and class variable in Ruby?
Instance variables versus class variables in Ruby: what @ and @@ actually mean, why an @ variable set at the class level stays empty when read from an instance, and how @@ values are shared by every instance. Short code samples make each behavior easy to verify.
What is cattr_accesor and mattr_accessor, thread_cattr or thread_mattr in Ruby and in Rails?
cattr_accessor, mattr_accessor, and the thread_cattr and thread_mattr variants explained: ActiveSupport helpers for class-level and module-level attributes, plus thread-safe versions that avoid data inconsistencies in multi-threaded apps. Examples for each accessor, reader, and writer.
Powerful switch statement with pattern matching in Ruby
Pattern matching in Ruby turns case statements into a precise switch over data shapes: match and destructure hashes from an API response, combine several patterns in one branch, capture values across patterns, and validate configuration. Ruby 2.7+ syntax examples.
Finding the slowest tests in Minitest and Rspec using profiler
Slow test suites usually hide a few expensive tests. Minitest and RSpec both ship a built-in profiler: bin/rails test --profile and rspec --profile 10 list your slowest examples with execution times, so you know exactly which tests to optimize first.
How to set up XML in Grape API
XML support in Grape API takes two steps: register the additional content_type so endpoints accept and return application/xml, then change the root element name of the XML output. Complete Ruby examples built around a products endpoint you can adapt to your API.
Multiple ways to execute a shell command via Ruby
Running shell commands from Ruby: system, backticks, exec, the IO class, spawn, and Open3.popen3 compared with pros and cons, from quick one-liners to capturing stdout, stderr, and exit status, so you can pick the right method for scripts and production code.
Solutions to paginate data in your databse and which one is the best
Database pagination goes beyond LIMIT and OFFSET: ROW_NUMBER(), the FETCH clause, and keyset pagination each behave differently as tables grow. SQL examples for every approach, why offsets get slow on big datasets, and a verdict on which method scales best.