Join Kevin Skoglund for an in-depth discussion in this video Understanding MVC architecture, part of Ruby on Rails 3 Essential Training.
In the last movie, I told you that Rails is structured in such a way that it helps us to write dry code. Remember, Don't Repeat Yourself. In this movie, I want you to take a closer look at that which is the MVC architecture that Rails employs. It's a fundamental aspect of Rails and it's important to understand right from the start. The M stands for Model. The V stands for View. The C stands for Controller. Now the model is our objects. It's the object-oriented approach design and it's actually encapsulates the data in our database as well, and we can treat those as objects The view is the presentation layer.
And it even might interact with the database. If it's database-enabled, it can pull things out of the database and then return that to the browser. Well an MVC architecture says well, instead of having this one page that's all muddied up with all of this different stuff going on in it, what if we broke it up? And we have the browser that communicates to the controller and just the code involved in making those decisions about what should happen based on those actions. That's what's going to be in the controller. Then if we need to interact with the database or any of our data, we will have the controller talk to our model and we will put all of our code relating to the data and to connecting with the database in the model.
The controller handles the decisions, the model handles the data and the view handles the presentation and we want to try and follow this architecture and keep our code in the right places. Decision code should go in the Controller, data code goes in the Model, presentation code goes in the View. Rails actually has names for these. It calls the controller, ActionController, and the view ActionView, the model is ActiveRecord. Not ActionRecord, ActiveRecord. So those are names we are going to become more familiar with as we work with Rails but that's what Rails calls its pre-built code to deal with these things.
So we are going to be accessing parts of ActiveRecord when we want to write things that deal with the model. Rails also packages together ActionController and ActionView as ActionPack. So if you were to see ActionPack, it's just ActionController and ActionView have been grouped together as one thing called ActionPack. So keep this architecture in your mind as we continue to work. We will come back and look at the diagram again but it will help you to understand how Rails structures things and what it's doing and most importantly where we should put our code.
- Understanding MVC (Model View Controller ) architecture
- Routing browser requests through the framework
- Responding to requests with dynamic content
- Defining associations and database relationships
- Creating, reading, updating and deleting records
- Working with forms
- Validating form data
- Reviewing built-in security features
- Authenticating users and managing user access
- Debugging and error handling
Skill Level Beginner
1. What Is Ruby on Rails?
2. Installing Ruby on Rails on a Mac
3. Installing Ruby on Rails on a Windows Machine
4. Getting Started
5. Controllers, Views, and Dynamic Content
6. Databases and Migrations
7. Models, ActiveRecord, and ActiveRelation
9. Controllers and CRUD
10. Layouts, Partials, and View Helpers
12. Data Validation
13. User Authentication
14. Improving the Simple CMS
15. Debugging and Error Handling
16. Introducing More Advanced Topics
- 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.