Member-only story
🚀 25 Unique Ruby on Rails Methods You Need to Know! ✨
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"]