Stefan Wille


10 Experience
0 Lessons Completed
0 Questions Solved


Posted in Sharing Data With Javascript Discussion

Hi Chris, thanks for this great video. One thing: I think the call to "render" needs to be surrounded by a call to "escape_javascript"( For instance:

<li class="nav-item btn-group" data-behavior="notifications" data-notifications="&lt;%= escape_javascript(render template: "notifications/index", formats: [:json]) %&gt;">

Or, shorter, using the alias "j":

<li class="nav-item btn-group" data-behavior="notifications" data-notifications="&lt;%=j render template: "notifications/index", formats: [:json] %&gt;">

Otherwise, a quote character in the generated JSON can break your HTML.

logo Created with Sketch.

Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

© 2021 GoRails, LLC. All rights reserved.