RSSAmplifier

Blog

Railscraft

Hone your Ruby on Rails craft. Tips, tricks, and articles from a professional engineer with 10+ years of experience.

railscraft.hashnode.devRSS feed ↗7 posts

Latest posts

💎 in the docs: ActionController#log_at

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 ...

Cleaner Rails Controllers with before_action

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...

Advice Comes with an Implied Asterisk

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...

Keep Your Controllers CRUD-y

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...

Consistently Handle Errors with a ModelErrors Concern

💡 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...

Rails Controller-Specific Middleware

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...

Safe Rails Selects with Bound Parameters

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...