Facebook comments (Facebook social plugin) is loaded only after updating the page in rails 4 applications

I have a rails 4 app and I want to use the Facebook social plugin for comments. I have this code: in show.html.erb I have

<div class="fb-comments" data-href="my site name" data-numposts="5" data-colorscheme="light"></div>

in application.js:

( function(d, s, id) {
        var js, fjs = d.getElementsByTagName(s)[0];
        if (d.getElementById(id))
            return;
        js = d.createElement(s);
        js.id = id;
        js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=644565478915600";
        fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));

And after my tag tag:

<div id="fb-root"></div>

When I go to the page, comments appear only after the update. Why?

+4
source share
3 answers

Remove Turbolinks. You can also install the jquery Turbolinks gem and then add // require jquery Turbolinks to the application.js file and remove // ​​require Turbolinks

+1
source

. , -, . . , , , (event.coffee , app/assets/javascript), . <div id="fb-root"></div>. , !

0

. , . Turbolinks. , : show.html.erb:

<% if current_page?(YOUR PATH) %> <body data-no-turbolink="true"> <% else %> <body> <% end %>

YOU PATH , Turbolink.

!

0

Source: https://habr.com/ru/post/1526830/


All Articles