🕵️♀️ Task
You can skip some records in the ActiveRecord::Relation set with .offset. This is useful for e.g. retrieving the second page of records, or choosing a random record.
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 |
|---|---|---|---|---|
| 311 | Woody Strode | 1914-07-25 | An athlete turned actor, St... | http://ia.media-imdb.com/im... |
| 312 | Jack Elam | 1920-11-13 | Colorful American character... | http://ia.media-imdb.com/im... |
| 313 | Keenan Wynn | 1916-07-27 | Character actor Keenan Wynn... | http://ia.media-imdb.com/im... |
| 314 | Frank Wolff | 1928-05-11 | Frank Wolff started his car... | |
| 321 | Sydney Greenstreet | 1879-12-27 | Sydney Greenstreet's father... | http://ia.media-imdb.com/im... |
| 322 | Peter Lorre | 1904-06-26 | As a youth Peter Lorre ran ... | http://ia.media-imdb.com/im... |
| 323 | S.Z. Sakall | 1883-02-02 | Hungarian-born S.Z. Sakall ... | http://ia.media-imdb.com/im... |
| 324 | Madeleine Lebeau | 1923-06-10 |
| id | actor_id | movie_id | name |
|---|---|---|---|
| 320 | 283 | 22 | Gluttony Victim |
| 321 | 284 | 22 | Dr. O'Neill |
| 322 | 285 | 22 | Coroner (as Reginald E. Cat... |
| 323 | 286 | 22 | Workman |
| 324 | 287 | 22 | Cab Driver |
| 325 | 288 | 22 | George, Library Night Guard |
| 326 | 289 | 22 | Library Guard (as Roscoe Da... |
| 327 | 290 | 22 | Library Guard |
Select all records from the persons table, EXCEPT the first 2 records
people = Person.all.where({ :current_city => "Chicago"})
people.offset(2)
=> #<Person::ActiveRecord_Relation:0x00007fa4341e1ee8>
Select all records from the dishes table, EXCEPT the first 20 records
Dish.all.offset(20)
=> #<Dish::ActiveRecord_Relation:0x00007fa4341e1ee8>