🕵️♀️ Task
You can limit the number of records in an ActiveRecord::Relation with .limit. You pass an Integer argument to choose the number of records you want to appear in the collection.
LevelUp
0.0% complete
LevelUp
0.0% complete
| id | title | year | duration | description | image | director_id |
|---|
| id | name | dob | bio | image |
|---|
| id | name | dob | bio | image |
|---|---|---|---|---|
| 325 | Dooley Wilson | 1886-04-03 | "You must remember this, a ... | http://ia.media-imdb.com/im... |
| 326 | Joy Page | 1924-11-09 | Actress Joy Page (nee Joy C... | http://ia.media-imdb.com/im... |
| 327 | John Qualen | 1899-12-08 | One of the best and most fa... | http://ia.media-imdb.com/im... |
| 328 | Leonid Kinskey | 1903-04-18 | Leonid Kinskey, originally ... | |
| 331 | Gabriel Byrne | 1950-05-12 | Byrne was the first of six ... | http://ia.media-imdb.com/im... |
| 332 | Benicio Del Toro | 1967-02-19 | Benicio Del Toro emerged in... | http://ia.media-imdb.com/im... |
| 333 | Kevin Pollak | 1957-10-30 | Born in San Francisco in 19... | http://ia.media-imdb.com/im... |
| 334 | Kevin Spacey | 1959-07-26 | As enigmatic as he is talen... | http://ia.media-imdb.com/im... |
| id | actor_id | movie_id | name |
|---|---|---|---|
| 328 | 291 | 23 | Clarice Starling |
| 329 | 292 | 23 | FBI Instructor |
| 330 | 293 | 23 | Ardelia Mapp |
| 331 | 294 | 23 | Agent Burroughs |
| 332 | 295 | 23 | Jack Crawford |
| 333 | 296 | 23 | Dr. Frederick Chilton |
| 334 | 297 | 23 | Barney |
| 335 | 298 | 23 | Friendly Psychopath |
Select the first 2 records from the persons table
Person.all.limit(2)
=> #<Person::ActiveRecord_Relation:0x00007fa4341e1ee8>
Select the first 10 records from the dishes table
Dish.all.limit(10)
=> #<Dish::ActiveRecord_Relation:0x00007fa4341e1ee8>