🕵️♀️ Task
On an ActiveRecord::Relation, the pluck method will retrieve one or more attributes of each record in the collection and returns them in a Array. You can pass one or more Symbols as an argument. Each Symbol must match the name of a column.
LevelUp
0.0% complete
LevelUp
0.0% complete
| id | title | year | duration | description | image | director_id | 
|---|---|---|---|---|---|---|
| 49 | The Departed | 2006 | 151 | An undercover state cop who... | http://ia.media-imdb.com/im... | 12 | 
| 50 | M | 1931 | 99 | When the police in a German... | http://ia.media-imdb.com/im... | 34 | 
| 52 | Dunkirk | 2017 | 106 | Allied soldiers from Belgiu... | https://m.media-amazon.com/... | 5 | 
| 51 | Interstellar | 2014 | 169 | A team of explorers travel ... | https://m.media-amazon.com/... | 5 | 
| id | name | dob | bio | image | 
|---|
| id | name | dob | bio | image | 
|---|---|---|---|---|
| 44 | Amanda Plummer | 1957-03-23 | The daughter of Christopher... | http://ia.media-imdb.com/im... | 
| 45 | Eric Stoltz | 1961-09-30 | Born on September 30, 1961 ... | http://ia.media-imdb.com/im... | 
| 46 | Bruce Willis | 1955-03-19 | Actor and musician Bruce Wi... | http://ia.media-imdb.com/im... | 
| 47 | Ving Rhames | 1959-05-12 | Irving "Ving" Rhames was bo... | http://ia.media-imdb.com/im... | 
| 48 | Phil LaMarr | 1967-01-24 | http://ia.media-imdb.com/im... | |
| 49 | Maria de Medeiros | 1965-08-19 | Maria de Medeiros is the ol... | http://ia.media-imdb.com/im... | 
| 50 | Rosanna Arquette | 1959-08-10 | Rosanna Arquette has acted ... | http://ia.media-imdb.com/im... | 
| 51 | Peter Greene | 1965-10-08 | Born in Montclair, New Jers... | http://ia.media-imdb.com/im... | 
| id | actor_id | movie_id | name | 
|---|---|---|---|
| 49 | 44 | 4 | Honey Bunny / Yolanda | 
| 50 | 45 | 4 | Lance | 
| 51 | 46 | 4 | Butch Coolidge | 
| 52 | 47 | 4 | Marsellus Wallace | 
| 53 | 48 | 4 | Marvin | 
| 54 | 49 | 4 | Fabienne | 
| 55 | 50 | 4 | Jody | 
| 56 | 51 | 4 | Zed | 
Retrieve the ages of each record in the persons table
Person.all.pluck(:age)
=> [42, 36, 22, 29, 27]
Retrieve the names of each record in the dishes table
Dish.all.pluck(:name)
=> ["Burger", "Mac & Cheese", "Kale Salad"]