π΅οΈββοΈ Task
You can access attributes of an ActiveRecord
object by using square brackets, []
, and the name of the column as a Symbol
or String
. Itβs similar to how you retrieve values from a Hash
by using keys.
LevelUp
0.0% complete
LevelUp
0.0% complete
id | title | year | duration | description | image | director_id |
---|---|---|---|---|---|---|
41 | Spirited Away | 2001 | 125 | In the middle of her family... | http://ia.media-imdb.com/im... | 30 |
42 | Modern Times | 1936 | 87 | The Tramp struggles to live... | http://ia.media-imdb.com/im... | 27 |
43 | North by Northwest | 1959 | 136 | A hapless New York advertis... | http://ia.media-imdb.com/im... | 21 |
44 | Back to the Future | 1985 | 116 | A teenager is accidentally ... | http://ia.media-imdb.com/im... | 15 |
45 | Citizen Kane | 1941 | 119 | Following the death of a pu... | http://ia.media-imdb.com/im... | 31 |
46 | The Shining | 1980 | 146 | A family heads to an isolat... | http://ia.media-imdb.com/im... | 28 |
47 | Life Is Beautiful | 1997 | 116 | A Jewish man has a wonderfu... | http://ia.media-imdb.com/im... | 32 |
48 | The Pianist | 2002 | 150 | A Polish Jewish musician st... | http://ia.media-imdb.com/im... | 33 |
id | name | dob | bio | image |
---|
id | name | dob | bio | image |
---|---|---|---|---|
41 | John Travolta | 1954-02-18 | John Travolta first gained ... | http://ia.media-imdb.com/im... |
42 | Samuel L. Jackson | 1948-12-21 | Samuel L. Jackson usually p... | http://ia.media-imdb.com/im... |
43 | Tim Roth | 1961-05-14 | Often mistaken for an Ameri... | http://ia.media-imdb.com/im... |
297 | Frankie Faison | 1949-06-10 | http://ia.media-imdb.com/im... | |
298 | Don Brockett | 1930-01-30 | ||
299 | Frank Seals Jr. | |||
300 | Stuart Rudin | 1941-12-16 | ||
330 | Stephen Baldwin | 1966-05-12 | http://ia.media-imdb.com/im... |
id | actor_id | movie_id | name |
---|---|---|---|
41 | 36 | 3 | Fanucci (as Gaston Moschin) |
42 | 37 | 3 | Rocco Lampone |
43 | 38 | 3 | Young Clemenza (as B. Kirby... |
44 | 39 | 3 | Genco |
45 | 40 | 3 | Young Mama Corleone (as Fra... |
46 | 41 | 4 | Vincent Vega |
47 | 42 | 4 | Jules Winnfield |
48 | 43 | 4 | Pumpkin / Ringo |
Select the tenth record from customers table and the retrieve the value from the email column
customer = Customer.all[9]
customer["email"]
=> "[email protected]"
Select the third record from Course table and the retrieve the value from the title column
course = Course.all[2]
course[:title]
=> "Application Development"