RubyCademy (@rubycademy) 's Twitter Profile
RubyCademy

@rubycademy

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

ID: 1047792827386810368

linkhttps://newsletter.rubycademy.com calendar_today04-10-2018 10:17:31

1,1K Tweet

3,3K Followers

0 Following

RubyCademy (@rubycademy) 's Twitter Profile Photo

Use the end-of-options marker (in yellow) to pass options to IRB directly! How it works: β†’ `rails c` starts the Rails console β†’ `--` tells Rails to stop parsing options β†’ `--noecho` is passed directly to irb #rubyonrails #irb

Use the end-of-options marker (in yellow) to pass options to IRB directly!

How it works:

β†’ `rails c` starts the Rails console
β†’ `--` tells Rails to stop parsing options
β†’ `--noecho` is passed directly to irb

#rubyonrails #irb
RubyCademy (@rubycademy) 's Twitter Profile Photo

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

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
RubyCademy (@rubycademy) 's Twitter Profile Photo

If I encounter one more `if ... then ... else ... end` block, I’ll go blind. πŸ‘€ Use the ternary operator instead! πŸ™ #rubyonrails #ruby

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

Use the ternary operator instead! πŸ™

#rubyonrails #ruby
RubyCademy (@rubycademy) 's Twitter Profile Photo

If you’re just swapping characters in a string, use `String#tr`, not `String#gsub`. πŸ’š Why? No regex engine, faster execution, cleaner intent. #rubyonrails

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

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

#rubyonrails
RubyCademy (@rubycademy) 's Twitter Profile Photo

Want to assign default values to locals in your Rails partials? With Rails 7.1+, you can do it right in the `locals:` pragma! #rubyonrails

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

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

#rubyonrails
RubyCademy (@rubycademy) 's Twitter Profile Photo

⚠️ Your booleans might be skipping validations… Did you know that `toggle!` calls `update_attribute` under the hood, which skips ActiveRecord validations? #rubyonrails #activerecord

⚠️ Your booleans might be skipping validations…

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

#rubyonrails #activerecord
RubyCademy (@rubycademy) 's Twitter Profile Photo

✨ FRESH BATCH OF CONTENT ✨ πŸ’Ž Faster string swaps β€’ Smarter loops β€’ Cleaner AI code πŸ”— rubycademy.com #rubyonrails

✨ FRESH BATCH OF CONTENT ✨

πŸ’Ž Faster string swaps β€’ Smarter loops β€’ Cleaner AI code

πŸ”— rubycademy.com

#rubyonrails
RubyCademy (@rubycademy) 's Twitter Profile Photo

Combine: - the `rails runner` command - with Bash heredocs to run multiline Rails scripts directly from your terminal! 🀩 PS: This is a common trick among seasoned Shell scripters. #rubyonrails

Combine:

- the `rails runner` command
- with Bash heredocs

to run multiline Rails scripts directly from your terminal! 🀩

PS: This is a common trick among seasoned Shell scripters. #rubyonrails