0

I'm passing a javascript function through the application.js in ruby on rails it work in the fisrt view but when I change to another view it doesn't load, just stay blank

this is the application.js :

//= require rails-ujs
//= require jquery
//= require turbolinks
//= require owl.carousel
//= require jquery.lazyload
//= require tinymce-jquery
//= require activestorage
//= require_tree .
    function addView(){
      atOptions = {
        'key' : 'xxxxxxxxxxxxxxxxxxxxx',
        'format' : 'iframe',
        'height' : 250,
        'width' : 300,
        'params' : {}
      };
      document.write('<scr' + 'ipt type="text/javascript" src="http' + (location.protocol === 'https:' ? 's' : '') + '://www.bcloudhost.com/ecd09eb0e13224fce209c614c8e4ea98/invoke.js"></scr' + 'ipt>');
    }

then I call this function in partial view like this: _article.html.erb

  <div class="side">
      <script type="text/javascript">
        addView();
    </script>
  </div>

this is the message that I got from the console

Uncaught DOMException: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.

I will really appreciate if you can help with this issue.

JULIO MACHAN
  • 161
  • 1
  • 2
  • 13

1 Answers1

0

First of all, you are trying to embed the script tag inside another. Secondly, you're just embedding a JS file in the document which doesn't seem to be helping on rendering anything on the webpage. If you can share your complete code snippet could help.

Also, looking at the error specified by you, it seems that your code trying to remove a dom element using its parent element. But here parent element does not contain the target element (which you are trying to delete) in its child dom tree. Hence, the error is thrown.

rustygb
  • 306
  • 1
  • 5
  • 13
  • Hi, the code as you can see it is how I have it in the project I just add that function in the application.js and I call it in the partial – JULIO MACHAN Oct 22 '19 at 22:15
  • @JULIOMACHAN The `addview` function call is just adding the `invoke.js` into your HTML document. If you add that script to normal HTML page, it doesn't return anything, shows a blank page. Also, atObject created before document.write is not used anywhere. May be more details on your code can help. – rustygb Oct 27 '19 at 18:57