Rails also lets us write custom query methods by saving them in a model as "named scopes." Named scopes can be called like ActiveRelation query methods and can be daisy-chained with other active ActiveRelation query methods.
- [Teacher] In this movie, we will learn…how to use named scopes in our models.…So far in this chapter, we've learned to create,…update, delete, and find records, and we did it…without adding any additional code to our model.…We've been using the built-in methods…provided by ActiveRecord and ActiveRelation.…Rails gives us these features for free,…simply by defining a model so that it inherits…from ActiveRecord::Base, which most of our models will.…You can also write your own query methods,…which can use and combine the built-in query methods.…We can design a query and then…save it in our models as a named scope.…
Named scopes assign a name to an ActiveRelation query…and then store them in a model.…We can call named scopes just like…we call ActiveRelation query methods,…and we can even daisy-chain them together…with other ActiveRelation query methods.…And they can accept parameters, just like a method would.…In Rails 5, we're gonna make sure that we define…these named scopes using something called the lambda syntax.…
- 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?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
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.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.