Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting second entry in rails console?

I need to select the second entry in the User model.

User.second does not work, nor does User.2 or User.two.

I'm trying to set u to the second User entry (u = User.2)

like image 967
StackExchange User Avatar asked Aug 18 '13 02:08

StackExchange User


1 Answers

The following should work:

User.all.second
User.offset(1).first

# Assuming you are using incremental keys and have users with ID's 1 and 2:
User.find(2)
like image 184
cmpolis Avatar answered Sep 25 '22 05:09

cmpolis