From the course: Ruby on Rails 6: Controllers and Views

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Capture content for later use

Capture content for later use - Ruby on Rails Tutorial

From the course: Ruby on Rails 6: Controllers and Views

Start my 1-month free trial

Capture content for later use

- [Instructor] Another useful feature is the ability to capture content for later use. We do that using two methods, content for and then we can also use content for? Content for will set the content we want to capture. Content for will just check and see if there is anything that has been captured. The way that we would use it is on a template page. We would call content for, and then an identifier for the content we want to capture. So in this example, I've got a symbol called script. That's now going to be the label on this content. And then the content I actually want to capture is inside that Ruby block, everything from do down to end. In this case, it's a little bit of JavaScript. It's going to pop up an alert. That's important to note that as it is, if this template were to render, it would not execute that JavaScript. It's not telling it to put that JavaScript on this page yet, it's telling it to capture it.…

Contents