Shpigford
Shpigford

Reputation: 25328

Find record by index in array?

So in the same way that you could do @items.active.first to get the first item, is there a way to select something else, like 56th?

Obviously @items.active.fiftysixth doesn't work, but is there some other method for accessing that?

Upvotes: 1

Views: 1898

Answers (1)

MrTheWalrus
MrTheWalrus

Reputation: 9700

When the collection is a relation, you can use offset (.first just translates to limit 1 in SQL)

@items.active.offset(55).first

Or, if it's an array:

@items.active[55]

Upvotes: 4

Related Questions