Stefan Wille
Joined
10 Experience
0 Lessons Completed
0 Questions Solved
Activity
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"(http://api.rubyonrails.org/.... For instance:
<li class="nav-item btn-group" data-behavior="notifications" data-notifications="<%= escape_javascript(render template: "notifications/index", formats: [:json]) %>">
Or, shorter, using the alias "j":
<li class="nav-item btn-group" data-behavior="notifications" data-notifications="<%=j render template: "notifications/index", formats: [:json] %>">
Otherwise, a quote character in the generated JSON can break your HTML.