facebook comments (Facebook social plugin) load only after I refresh the page in rails 4 app

Good day Alex, I'm trying to add facebook comment plugin enabled and it works but the problem is i need to refresh the page in order the comments appear. I don't think removing Turbolink is ideal, so any idea? ################### <div id="fb-root"></div> <script>(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_US/sdk.js#xfbml=1&version=v2.0"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk'));</script> #####################################################

Posted over 4 years ago by MO. H.
Posted over 4 years ago by Alex Yang

Removing turbolinks is actually not such a bad idea (e.g. turbolinks is mostly disabled on the BaseRails website). You can also disable turbolinks on a page-by-page basis or for specific links, rather than on your entire site. Let me show you what I mean:

To disable turbolinks on your entire site, go to your application layout file and change the <body> to <body data-no-turbolink="true">.

To disable turbolinks on a specific view page (say index.html.erb), go to that file and add the following at the top:

<% content_for(:body_attributes) do %>
data-no-turbolink="true"
<% end %>

2
Posted over 4 years ago by MO. H.

Hmmm, it's just weird. i added the content_for tag at show.html.erb file and still not working; i still have to re-fresh the page. Also, i installed gem 'jquery-turbolinks' and still no luck. If i remove turbolink completely, it work but disabling turbolink is not working. Not sure what's going on ?!

1
Posted over 4 years ago by Alex Yang

Another approach you can try instead is to add an 'if statement' to your application layout file. For example, you could write:

<% if current_page?({PATH_NAME}) %>
<body data-no-turbolink="true">
<% else %>
<body>
<% end %>

In this example, {PATH_NAME} should be the Rails path that corresponds to that specific view page (e.g. listings_path).

Finally, keep in mind that these are all pretty general examples. It's possible (though unlikely) that the specific Facebook plugin you're using is interfering somehow.

1
Posted over 4 years ago by MO. H.

still no luck, anyways as you mentioned earlier, it's not really a big deal so i just removed it, i don't feel the difference really. Thanks Alex.

1