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

Use instance variables to set values in the template - Ruby on Rails Tutorial

From the course: Ruby on Rails 6 Essential Training

Start my 1-month free trial

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…

Contents