Rake is a task runner written in Ruby. It performs repetitive tasks, such as 1. Making database backup 2. Running tests 3. Watch for file changes and compile the changed files In the words of late Jim Weirich, the creator of rake, The essence of rake is to take a| Write Software, Well
Let's say you want to add non-resourceful custom routes on your controller. Most often, you're better off by introducing a new resourceful controller. However, in those cases where you absolutely have to, you can define new routes using the member and collection blocks provided by the Rails router.| Write Software, Well
If you want to quickly try out some Rails feature or code in the browser without spinning up a whole new controller and a view, simply map the incoming request to a lambda Rack endpoint, i.e. a lambda that returns the status, headers, and response body.| Write Software, Well
Do you want to read the Rails source code for a deeper understanding of the framework, but feel intimidated by the sheer size of the codebase, or don't know where to start? Start with a specific feature, insert a breakpoint, and step through the method line-by-line. This article shows how.| Write Software, Well
Do you want to understand how Active Job works behind the scenes? Reading and understanding the source code is one of the best ways to learn a framework (or anything). This post breaks it all down for you by tracing the journey of a Rails background job, from its creation to execution.| Write Software, Well
A staging environment is a safe replica of production where you can test features before going live. In this post, we'll create a staging environment for the blog and deploy to it with Kamal. It also covers the basics of Rails environments and shows how to configure Kamal for staging deployments.| Write Software, Well
In this post, I'll provision and configure the staging infrastructure for my blog, which is a Rails application. This includes installing and setting up a PostgreSQL database server, allowing connections only from the Rails application server, and locking it down by disabling direct public access.| Write Software, Well
This is the first post in the series where I'm building my blog in Ruby on Rails. I'll create a new Rails application and we'll walk through some of the important files and directories in a fresh Rails project. By the end of this post, we'll have a basic app up and running in the browser.| Write Software, Well
After three years on Ghost, I'm rebuilding this blog from scratch with Ruby on Rails. In a new series, I'll document the journey of building a production Rails application, from development to deployment. Follow along as I build the new home for Write Software, Well.| Write Software, Well
A sitemap lists your site's pages, helping Google crawl it efficiently. It's especially useful for large sites or new sites with zero backlinks. This post shows how you can create one in your Rails site, how to add it to Google Search Console, and how to index new pages as soon as you publish them.| Write Software, Well
The Rails router's direct method lets you create custom url and path helpers, which is especially useful for polymorphic models and delegated types. This post shows how to use a single custom helper to generate URLs for different models, with a practical example from the open source Maybe project.| Write Software, Well
I started as a sceptic, but now I'm a convert and a heavy user of AI for everyday programming, and wanted to write down some common patterns and prompts for working with AI tools that I’ve found useful in my own development workflow as well as those I learned from other experienced developers.| Write Software, Well
This post shows how to inspect the sequence of before, after, and around callbacks in Rails controllers by adding a small initializer. Useful for understanding callback order in applications with complex controller hierarchies or shared concerns. I learned this trick while reading the Rails tests.| Write Software, Well
You can safely extract options hash from the end of an argument list using the extract_options! method in Rails. Not only it simplifies the method definition but it keeps the method's API flexible, allowing you to add new options without breaking existing callers.| Write Software, Well
Last week, I used AI to finally learn the basics of QuickBooks and handle my company’s bookkeeping. AI didn’t just help me finish a chore, it taught me a skill I’d been avoiding for years. When used with intent, the modern AI tools can accelerate your learning in surprising ways.| Write Software, Well
Announcing a new newsletter where I write about topics beyond Ruby on Rails: running a software services business, freelancing, positioning and marketing for developers, working with AI, hiring and tech recruiting, etc. Business Logic is about everything that happens around writing software, well.| Write Software, Well
If your Rails app deals with large files, let a reverse proxy like Nginx or Thruster serve them. In this post, we'll learn how X-Accel-Redirect (or X-Sendfile) header hands off file delivery to Nginx. We'll also read Thruster’s source code to learn how this pattern is implemented at the proxy level.| Write Software, Well
Spreading the joy of writing software using Ruby and Rails with the world.| Write Software, Well
After three years of freelancing and over a year of running my own software studio, here're some scattered thoughts on freelancing as a software developer, especially around web development.| Write Software, Well
Concerns are an important concept in Rails that can be confusing to understand for those new to Rails as well as seasoned practitioners. This post explains what concerns are, how they work, and how & when you should use them to simplify your code, with practical, real-world examples.| Write Software, Well
Spreading the joy of writing software using Ruby and Rails with the world.| Write Software, Well
This article explains the Rails rendering process in the context of returning JSON data from the controller. Hopefully, it will make it clear what really happens when you call the render method from the controller.| Write Software, Well
In this post, we’ll explore how redirects work in Rails: what they are, how to redirect manually, and how the redirect_to method simplifies things. We’ll cover common use cases, security considerations, and even dig into the Rails source to see how redirect_to works under the hood.| Write Software, Well
In this post, we'll learn how Rails' render method works and how to use it effectively. From rendering templates, partials, and inline content to JSON and custom status codes, this post explores the different ways to render views from your controllers.| Write Software, Well
In this post, we'll learn how to use a SQL subquery in a Rails app to eliminate N+1 queries and improve performance. We'll profile a real-world example, showing how to fetch a single record from associated has_many records efficiently without eager loading or excessive memory usage.| Write Software, Well
As your application grows, so do your database tables. If you keep fetching all columns, those extra fields, especially large text or JSON blobs can quietly eat up a lot of memory. This post shows how to reduce memory usage in your Rails apps by selecting only the columns you need from the database.| Write Software, Well
This post shows how you can get a better understanding of your Ruby on Rails application performance with the Rails Debugbar, a profiling tool inspired by Laravel Debugbar. It also covers how to spot N+1 queries, reduce object allocations, and optimize SQL queries to improve page load times.| Write Software, Well
In 2012, GitHub was compromised by Mass Assignment vulnerability. A GitHub user used mass assignment that gave him administrator privileges to none other than the Ruby on Rails project. In this post, I will explain this vulnerability and how you can use the Rails strong parameters API to address it.| Write Software, Well
In this post, we'll learn how to work with the response object in Rails controllers — from inspecting response bodies and headers to setting status codes and content types. This guide also covers key methods like body, status=, content_type, cookies, and more, with practical examples.| Write Software, Well
Every web application needs to process incoming HTTP requests. In this post, we’ll take a closer look at how Rails handles requests, how you can access the request object in the controller, and some of the most useful methods it provides to gather meaningful data from the request.| Write Software, Well
This is the first post in a new series that explores the Rails controllers in detail. This post covers the basics, providing a brief overview of controllers, why we need a controller, and how to create one. We'll start exploring more advanced stuff about controllers starting from the next post.| Write Software, Well
The dependent: :restrict_with_error option is a simple way to enforce data integrity in Rails apps. By preventing deletions of parent records with existing associations and providing helpful errors, it ensures historical data remains intact while guiding users on how to handle dependencies properly.| Write Software, Well
Spreading the joy of writing software using Ruby and Rails with the world.| Write Software, Well
A root route specifies what should happen when someone visits the home page of your application. This post shows how to add a root route.| Write Software, Well
This post shows how you can redirect incoming HTTP requests using the Rails router with the help of the redirect() method.| Write Software, Well
This post walks through backing up a SQLite database inside a Docker container on a remote server, specifically for a Ruby on Rails application deployed with Kamal. We'll begin with the basic commands, then convert them into a reusable shell script and a Rake task for convenience.| Write Software, Well
Rails is great for building web apps. But it can be quite overwhelming if you don't know how web applications work. In this series of articles, we'll build a simple but complete app in plain Ruby without Rails, to get a deeper understanding and appreciation of everything Rails does for us.| Write Software, Well
The Instrumentation API in ActiveSupport serves a dual purpose. You can use it to implement the observer (pub-sub) pattern, as well as benchmark how long it took to execute some action. In this post, we'll learn almost everything you need to know about the Rails Instrumentation API.| Write Software, Well
Map a Resourceful Route in Rails to Another Controller Class| www.writesoftwarewell.com
Shallow nesting lets you avoid deep nesting by generating the collection actions scoped under the parent, but by not nesting the member actions.| Write Software, Well
If you want to map a resourceful route to another controller class in Rails, you can do so by passing the controller option to the resources method.| Write Software, Well
Rails allows you to nest a resource within another resource to express the logical relationship between them. This post shows how nested resources work in Rails.| Write Software, Well
You can list all the routes in your Rails application by running the `bin/rails routes` command in the terminal. or by visiting `/rails/info/routes` path on a running Rails application.| Write Software, Well
In this post, we will learn about the match method, which forms the core of the Rails router. We'll also explore how the match method works behind the scenes. Once you really understand the match method and its options, the rest of the routing methods and shorthands become very easy to understand.| Write Software, Well
This post shows how you can override the default named parameter :id in Rails, by overriding the `to_param` method on the Rails model.| Write Software, Well
This post explains named routes in Rails. We'll learn how you can name a route, and how you can use the named helper methods to generate URLs corresponding to the route.| Write Software, Well
In this course, we'll build a web application in Ruby from scratch, without using Rails, to understand how web applications work and the core ideas behind Rails. In each lesson, we will build a specific feature from scratch using Ruby and understand the corresponding Rails concept in-depth.| Write Software, Well
Hotwire, which stands for HTML Over the Wire, provides a different way to build modern web applications without using too much JavaScript. This article provides a quick introduction to Hotwire and its component frameworks, such as Turbo Drive, Frames, and Streams.| Write Software, Well
Metaprogramming in Ruby enables you to produce elegant, clean, and beautiful programs as well as unreadable, complex code that’s not maintainable. This book teaches you the powerful metaprogramming concepts in Ruby, and how to use them judiciously.| Write Software, Well
Gain a better and deeper understanding of the Ruby on Rails framework by exploring how it works behind the scenes. Each post in this series takes a feature in Rails and shows how it's implemented behind the scenes.| Write Software, Well
The word Rack actually refers to two things: a protocol and a gem. This article explains pretty much everything you need to know about Rack as a Rails developer. We will start by understanding the problem Rack solves and move to more advanced concepts like middleware and the Rack DSL.| Write Software, Well
You must have used concerns in Rails. Did you know you can also use concerns for your routes? They allow you to declare common routes to be reused in other resources and routes. This post covers the basics of routing concerns, including what they are, how they work, and when you might need them.| Write Software, Well
Counting the number of commits after a specific commit in Git is a common task when you make small but frequent commits and need to squash them before rebasing from the main branch. This post shows one simple way to do this in git. Let me know if you know a better solution.| Write Software, Well
For the past few days, I've been trying to learn everything I could about the Rails router. I compiled all of my notes together with the past articles on this blog, and published a handbook on the router. I hope you find it useful and you learn a thing or two about the incredible Rails Router.| Write Software, Well
This post shows how you can access the raw, unaltered request body using a 20-year old method in the Rails framework (from the founder of Shopify). The `raw_post` method reads the request body, and is useful for web services or API controllers that need to directly work with raw requests.| Write Software, Well
Polymorphic associations in Rails allow a single model to belong to multiple models. This article covers them in-depth. We'll start with understanding the concept of polymorphism, learn what a polymorphic association is, why we need them, how they work, and how to use them in your Rails application.| Write Software, Well
This post contains my notes and highlights from the Shape Up from 37signals. It contains practical and actionable advice on project management, planning, and actually shipping meaningful work. I found it a great alternative to traditional practices like Agile. Give it a try on your next project!| Write Software, Well
This article shows how you can access your application models and other constants inside rake tasks by adding the `environment` task as a dependency. We'll also go one level deeper and learn exactly how this task loads the environment by inspecting the Rails source code.| Write Software, Well
Rails parameters let you access data sent by the browser, both via the URL and forms. In this article, we'll cover the basics of parameters, including what they are, how they work, and why they're important. We'll also learn how you can pass parameters in different formats such as arrays and hashes.| Write Software, Well
The concept of resourceful routing took me a long time to understand, but once it clicked, it changed how I viewed web applications. This post covers the basics: what a resource is, the routes it generates and how resourceful routing provides a nice organizational structure your Rails applications.| Write Software, Well
With my current projects wrapping up, I have the capacity to take on at least one or two new freelance projects, and I can devote my full attention for 20-30 hours each week per project. If you (or your team) are looking for a freelance Ruby and Rails developer, please reach out to me via email.| Write Software, Well
The Rails router can dispatch an HTTP request to a Rack endpoint, either in your application or within a gem. This is useful when you want to provide a well-isolated web UI or front-end to the users of your gem. In this post, we'll learn why you may want to do this, how it works, and how to do it.| Write Software, Well
Here're two techniques I've found really helpful for reading the Rails codebase, without getting overwhelmed. If you want to dive into the Rails source code for a deeper understanding, but feel intimidated by the sheer size of the codebase and don't know where to begin, this post is for you.| Write Software, Well
In this post, we will explore how a simple Ruby method, when added to a controller, becomes an action in Rails, ready to process incoming HTTP requests and send responses. We'll also trace the path of an incoming HTTP request to a Rails controller action.| Write Software, Well
The router is the entry point of your Rails application. It acts as the gatekeeper for all incoming HTTP requests, inspecting and sending them to a controller action; even filtering and rejecting them if necessary. In this article, we’ll do a deep dive into the Rails Router to understand it better.| Write Software, Well
In this article, we will build a counter component using the Stimulus JavaScript library. This simple example will demonstrate a bunch of useful features of Stimulus such as managing state, handling events, and targeting DOM elements.| Write Software, Well
A Hash is a built-in data structure in Ruby that maps values to keys and has a constant-time O(1) lookup. This article shows the capabilities of this simple, but equally powerful tool. We’ll start with the basics but also cover some obscure but equally useful features of hash.| Write Software, Well
Base64 is an elegant way to convert binary data to text, making it easy to store and transport. This article covers the basics of Base64 encoding, including what it is, how it works and why it's important. It also shows how to encode and decode Base64 data in various programming languages.| Write Software, Well
The database schema evolves continuously. Rails migrations is a powerful and flexible way to update the schema without dropping and re-creating the database. However, all this power and flexibility can be overwhelming. Here's a handy cheatsheet for most common migration operations.| Write Software, Well