From the course: Ruby on Rails 5 Essential Training

Unlock the full course today

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

JavaScript tag and sanitizing

JavaScript tag and sanitizing - Ruby on Rails Tutorial

From the course: Ruby on Rails 5 Essential Training

Start my 1-month free trial

JavaScript tag and sanitizing

- [Narrator] In the previous movie, we learned to include JavaScript files which are being managed by asset pipeline. Before we move on, I want us to also see another way of adding JavaScript content to your templates and then learn how to sanitize content for use in JavaScript. There's a second JavaScript helper method which is used when you want to put JavaScript directly on a page, that's different than loading in a full file of JavaScript. Typically you load in a whole file when you have a lot of JavaScript and you use the second helper when you just need to load in a very small bit. So here I just have a single one line alert "are you sure." There's also a block format that you can use if you need to have slightly more room to write your JavaScript. So you can just put all of your JavaScript between do and end. You're essentially dropping into JavaScript mode with everything that's inside of there. The end result is that it's going to output content to the browser inside script…

Contents