Ruby classes can utilize accessor methods to allow reading and writing values to instance variables. Rails will automatically create accessor methods for all table columns.
- [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 cumbersome,…especially if we have a database…
- Creating and configuring a new Ruby on Rails project
- Generating controllers and views
- Handling server requests
- Using different types of routes
- Rendering and viewing templates
- Generating migrations and models
- Creating, updating, and deleting records
- Finding records with queries
- Understanding relationship types
- Writing controllers for CRUD
- Working with layouts and helpers
- Managing application assets
- Building forms
- Validating data
- Authenticating users
Skill Level Beginner
1. What Is Ruby on Rails?
2. Get Started
3. Controllers, Views, and Dynamic Content
4. Databases and Migrations
5. Models and ActiveRecord
7. CRUD, REST, and Resourceful Routes
8. Controllers and CRUD
9. Layouts, Partials, and View Helpers
12. Data Validation
13. Controller Features
14. User Authentication
15. Improve the Simple CMS
Next steps1m 44s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.