K
K
Karina2016-01-07 16:19:30
Ruby on Rails
Karina, 2016-01-07 16:19:30

How to include js script only once?

I have a multilingual application. The problem is - as soon as I go to the page with locations - everything is fine. But if I want to change the language -
<%= link_to image_tag('en.png'), locale: 'en' %>
Then they write to me that it is impossible to connect the google maps api several times - You have included the Google Maps API multiple times on this page. I tried to connect this script both in my specific page and in application.js - The result is the same - the same error.
There was a thought - first initialize the variable with zero and increment this variable for each click, and if this variable is not zero, then do not connect the script with google maps. But I could not pull out a variable from js in view. This is real?
Thanks everyone for the replies.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MistaTwista, 2016-01-11
@iKapex

If Turbolinks is used, Evaluting script tags might help . Turbolinks keeps a cache of pages and doesn't always execute scripts in an obvious way. For some pages, it can be turned off altogether.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question