Mannish
Mannish

Reputation: 139

Refer few Ids through the index action

While we refer to all the datas in the model through index action in our controller as

for example

@task = Task.all

How to refer to the first three data's in the model database which we want to use. Like finding arrays like

@task =  Task.find(id: [1,2,3])

Is it possible to only get the three first data.

Thank you

Upvotes: 0

Views: 31

Answers (1)

Michael Gorman
Michael Gorman

Reputation: 1077

The rails first method can take a parameter of how many you want

@task = Task.first(3)

Upvotes: 1

Related Questions