From the course: Ruby on Rails 6 Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Use instance variables to set values in the template - Ruby on Rails Tutorial
From the course: Ruby on Rails 6 Essential Training
Use instance variables to set values in the template
- [Instructor] In this movie, we'll learn to use instance variables to allow the controller to provide data to the template. Let's go back to the MVC diagram again. One of the primary responsibilities of the controller is going to be to gather data from the models and from the database. Once it's done that, it needs to make that data available to the view template so it can be presented back to the browser. A good way to think of this relationship is to imagine a rock concert. There's a guitar tech who tunes all the guitars and sets them up on stage ahead of time. There may be different guitars for different songs. During the concert, the guitarist just has to walk over and pick up the guitar and play. The guitar tech took care of everything else ahead of time to make it easy for the guitarist to put on a good show. That is similar to the relationship between the controller and the view. The controller sets everything up…
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
-
-
-
-
-
Render a view template for a browser5m 35s
-
Redirect controller actions5m 13s
-
Define view templates using HTML5m 34s
-
Use instance variables to set values in the template3m 42s
-
Create links to other webpages4m 17s
-
Defining and reading URL parameters6m 38s
-
Challenge: Dynamic templates3m 22s
-
Solution: Dynamic templates6m 9s
-
-
-
-
-
-