Sign up for my newsletter
Let's learn to become better developers.
How to Create a Form with Multiple Submit Buttons to Different URL Endpoints
Although it's uncommon, there're a few cases where you need to submit a form to different endpoints. This post shows how you can create a form that has more than one submit buttons, each of which submits to a different URL endpoint. The formaction attribute on the button elements let you submit the form to a different URL endpoint. Additionally, you can use formmethod attribute to override the parent form's method.
June 03, 2023
Generating Secure Tokens on Your ActiveRecord Models
You must have used the `has_secure_password` macro in Rails. Did you know Rails also provides a `has_secure_token` macro to generate unique tokens on your models? In this article, we'll learn how it works and we'll also see how Rails implements it behind the scenes.
May 31, 2023
How to Render Markdown Views in Rails
This article shows how to create and render markdown views in Rails. This is useful if you have a few static marketing pages in your web application that you'd like to save and edit as markdown along with the rest of your code files.
May 25, 2023
Concerns in Rails: Everything You Need to Know
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.
May 20, 2023
How to Create Custom Flash Types in Rails
While reading the Rails codebase last week, I came across a useful method that lets you create custom flash types. In this post, we'll learn how to use it and also how it's implemented behind the scenes. In the process, we'll also learn a few metaprogramming tricks in Ruby.
May 17, 2023
Inline Routes in Rails
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.
May 15, 2023
Simplifying My Blogging Workflow with Ruby
This is the 100th post on this blog 🎉 I wanted to share how a simple Ruby script simplified my blogging workflow and dramatically increased the number of posts I write on my various blogs.
May 13, 2023
Did You Know that You Can Catch and Throw Stuff in Ruby?
Unlike traditional programming languages, Ruby's throw and catch are not used to raise and catch exceptions. Instead, they let you escape from deeply nested control flows. This post shows how `throw-catch` works in Ruby with practical, real-world examples, including their usage by the Warden gem.
May 09, 2023
Various Ways to Run Shell Commands in Ruby
Ruby provides multiple ways to conveniently execute external processes from the code. In this article, we'll learn all the ways you can run shell commands in Ruby and also consider various circumstances under which you'd choose one over the other.
April 29, 2023
Ruby's Switch Statement is More Flexible Than You Thought
Ruby's switch statement is very versatile and flexible, especially due to the dynamic nature of Ruby. In this post, we'll see how you can use it in various ways. We'll also learn why it works the way it works. Hint: it uses the `===` operator (method) under the hood.
April 25, 2023