From the course: Ruby on Rails 5 Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Model attributes - Ruby on Rails Tutorial
From the course: Ruby on Rails 5 Essential Training
Model attributes
- [Instructor] In this movie, we will learn how model attributes work. If we were working with a pure Ruby class, we would need to define any attributes on the object using code something like this. I'm actually defining two attribute accessors here. I'm defining them two different ways. The first is the shorthand. I'm calling attr_accessor, and then :first_name to tell it that the name of the attribute should be first_name. That will allow me to read and write to the variable first_name on this class. Or I can write it out the longer way, which really shows what's going on. I can have a reader, which is last_name and it just returns the value of the instance variable last_name. And I can have a writer method, which sets a value equal to last_name, so last_name equals some value. We'll set the instance variable last_name equal to a value. These do the same thing. So they're equivalent, first_name and last_name would behave the same. But I had to write them out, and that's very…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
ActiveRecord and ActiveRelation4m 32s
-
(Locked)
Model naming5m 52s
-
(Locked)
Model attributes2m 51s
-
(Locked)
The Rails console3m 17s
-
(Locked)
Create records4m 53s
-
(Locked)
Update records3m 16s
-
(Locked)
Delete records2m 29s
-
(Locked)
Find records5m 48s
-
(Locked)
Query methods: Conditions7m 39s
-
(Locked)
Query methods: Order, limit, and offset6m 29s
-
(Locked)
Named scopes8m 26s
-
(Locked)
-
-
-
-
-
-
-
-
-
-
-