facebook comments plugin showing only after refresh

倖福魔咒の 提交于 2019-12-07 19:30:04

问题


I am trying to use the facebook comments plugin.

I have this code, I have added after the opening <body> tag and also tried before de closing </body> like suggested here

<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&appId=MY_APP_ID&version=v2.0";
          fjs.parentNode.insertBefore(js, fjs);
        }(document, 'script', 'facebook-jssdk'));
        </script>

And on the 'show' page I have <div class="fb-comments" data-href="<%=request.original_url %>" data-numposts="5" data-colorscheme="light"></div>

The problem is that the plugin only shows when I refresh the page, not when I access the page through a link from the same site.

EDIT:

I discovered is has to do with turbolinks, I uninstalled it and it worked, I would like to find a solution with turbolinks installed. I tried this solution but couldn't make it work


回答1:


I had same problem. You need to turn off your turbolinks. Go the link where people are using to access the page and turn it off there. For example:

<%= link_to 'Use', model, class: "btn btn-primary", :"data-no-turbolink" => true %>

:"data-no-turbolink" => true

will do this for you. It's a known problem when combining JS with Rails.



来源:https://stackoverflow.com/questions/23773804/facebook-comments-plugin-showing-only-after-refresh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!