RubyCademy's Avatar

RubyCademy

@rubycademy.bsky.social

The best Ruby code examples. For more PRO Tips and foundational knowledge: πŸ”— https://www.rubycademy.com

37 Followers  |  0 Following  |  7 Posts  |  Joined: 25.04.2025  |  1.0798

Latest posts by rubycademy.bsky.social on Bluesky

Post image

πŸ”— www.rubycademy.com πŸ’š

15.05.2025 09:49 β€” πŸ‘ 1    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Post image

⚠️ Your booleans might be skipping validations…

Did you know that `toggle!` calls `update_attribute` under the hood, which skips ActiveRecord validations?

#rubyonrails #activerecord

01.05.2025 18:07 β€” πŸ‘ 2    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Post image

Want to assign default values to locals in your Rails partials?

With Rails 7.1+, you can do it right in the `locals:` pragma!

πŸ”— www.rubycademy.com

#rubyonrails

01.05.2025 13:43 β€” πŸ‘ 2    πŸ” 0    πŸ’¬ 1    πŸ“Œ 0
Post image

If you’re just swapping characters in a string, use `String#tr`, not `String#gsub`. πŸ’š

Why? No regex engine, faster execution, cleaner intent.

#rubyonrails

29.04.2025 16:11 β€” πŸ‘ 17    πŸ” 3    πŸ’¬ 0    πŸ“Œ 0
Post image

If I encounter one more `if ... then ... else ... end` block, I’ll go blind. πŸ‘€

Use the ternary operator instead! πŸ™

#rubyonrails #ruby

29.04.2025 14:37 β€” πŸ‘ 1    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Screenshot of news for All about code and Ruby from inside the newsletter

Screenshot of news for All about code and Ruby from inside the newsletter

Find out what's new inside πŸ‘‰ All about Code and Ruby from @byroot.bsky.social , @bramjetten.dev @tenderlove.dev Vishnu M @hasumikin.bsky.social @jamie.schembri.me @Josef Strzibny @Matt Swanson @johnnunemaker.com @rubycademy.bsky.social and many more

28.04.2025 12:16 β€” πŸ‘ 4    πŸ” 3    πŸ’¬ 1    πŸ“Œ 0
Post image

Rails 8 introduced `rate_limit` for controllers.

You can combine it with a `handle_rate_limit` method + a `BusyController` to centralize how you respond to throttled requests.

Keeps things clean and makes it super easy to extend later.

#rubyonrails

28.04.2025 15:42 β€” πŸ‘ 2    πŸ” 1    πŸ’¬ 0    πŸ“Œ 0
Post image

"Rails is dead," they said! πŸ˜‚ #rubyonrails

25.04.2025 18:26 β€” πŸ‘ 3    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0