Tell Rails Which Record You Want

Mar 26, 2015

Did you know you can tell ActiveRecord which record you want in plain english up to the fifth record? I didn’t.

User.first

User.second

User.third

User.fourth

User.fifth

All of these return the record you asked for. This is great for playing in the console and needing a specific record. I use this all the time when developing with just few records.

If you enjoyed this and would like to be notified the next time I write something, you can subscribe with your choice of RSS or Email.

I promise not to spam you and you can unsubscribe at anytime.

Also, here are some other items you might like longer longer:

or go see everything in the archive.