Member-only story

🚀 25 Unique Ruby on Rails Methods You Need to Know! ✨

Lakhveer Singh Rajput
CodeX
Published in
3 min readNov 18, 2024

Ruby on Rails is renowned for its elegance and simplicity, providing developers with powerful tools and methods to build applications quickly and efficiently. While some methods are commonly known, Rails also packs a bunch of unique and lesser-known gems that can save you hours of work! Let’s dive into 25 unique Ruby on Rails methods every developer should know, complete with explanations and examples. 🛠️

1. present? and blank? 🤔

Determine if an object is present or empty. These are much smarter than nil? and work for strings, arrays, hashes, and more.

name = "Ruby on Rails"
puts name.present? # true
puts "".blank? # true

2. squish 🧹

Removes all leading, trailing, and excessive inner whitespace from a string. Perfect for cleaning up messy input!

messy_string = "  Too    much   space!  "
puts messy_string.squish # "Too much space!"

3. pluck 🌱

Fetch specific fields directly from the database without loading full objects. It’s a game-changer for performance optimization.

User.pluck(:name) # ["Alice", "Bob", "Charlie"]

4. in_groups_of 📦

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

CodeX
CodeX

Published in CodeX

Everything connected with Tech & Code. Follow to join our 1M+ monthly readers

Lakhveer Singh Rajput
Lakhveer Singh Rajput

Written by Lakhveer Singh Rajput

Ruby on Rails enthusiast, book lover and DevOps explorer. Follow me for insights on coding, book recommendations, and bridging development with operations.🚀📚

Responses (1)

Write a response