Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails turbolinks load javascript on single page

I have a rails application using turbolinks

one page i should load script, and i don't want load it on all the application

specific add it on page like that

 <% content_for :head do %>
 <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<% end %>

my problem is while i enter to page via turbolinks the script doesn't load

how can i load single js on specific page

thanks!

like image 399
24sharon Avatar asked Aug 24 '13 18:08

24sharon


2 Answers

Turbolinks will NOT update head. That's where the advantage is. The loading speed will be much faster without head reloading. That's why your content_for :head won't work.

For your case, the simplest solution is to put the script tag directly on page template.

like image 121
Billy Chan Avatar answered Oct 21 '22 16:10

Billy Chan


Maybe adding data-no-turbolink to your script tag helps you.

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false" data-no-turbolink></script>
like image 28
user3631047 Avatar answered Oct 21 '22 15:10

user3631047