I love digging through the docs and finding an example that kind of explodes your brain a bit—some piece of functionality you might otherwise gloss over. Take this one from the Rails docs for log_at. At first glance, I didn’t realize how useful this ...
If you have two or more render statements in your controller action, you might consider extracting some of the logic into a before action. Why? Because rendering or redirecting in a before_action will halt the request cycle and remove the need for an...
In software development we’re often given advice in absolute terms: “Service Objects are an anti-pattern.” “Keep your controllers skinny.” “Vanilla Rails is enough.” In the Ruby on Rails community, we all know DHH has a reputation for writing wi...
Anytime your controllers start to accumulate non-standard CRUD (Create, Read, Update, Delete) action names, you may consider extracting the action into a new controller where the action can become one of the standard CRUD action names. Often times, y...
💡 Trigger Warning! This approach may be considered controversial, especially since it touches on using exceptions for control flow. This is a pattern you can use in your Rails projects to keep your controllers lean. It works especially well in Rai...
Did you know you can set controller-specific middleware in your Rails controller with the use method? I found this while looking through the docs for ActionController::Metal. https://api.rubyonrails.org/classes/ActionController/Metal.html#method-c-us...
Recently, we were trying to write a similarity(...) query in Postgres, and needed to pass in a parameter into a SELECT clause. Brakeman came back saying that we had a Possible SQL Injection. After looking at the code, we were directly interpolating t...