Disqus comments fails to load on localhost?

2019-01-17 06:55发布

问题:

I would like to use the universal code and have ran into difficulties getting the most basic functionality done.

I would like to create a shortname for test and one for my deployment, which I did from the Disqus admin panel.

Here is the disqus code in my show action:

# inside show.html.erb
<%= render raw 'comments' %>

# partial "comments"

  <div id="disqus_thread"></div>
    <script type="text/javascript">
      var disqus_shortname = '<%= Post::DISQUS_SHORTNAME %>';
      var disqus_identifier = '<%= @post.id %>';
      var disqus_url = '<%= url_for([:blog, @topic, @post])%>';
        (function() {
            var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
            dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
            (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
        })();
    </script>
    <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
    <a href="http://disqus.com" class="dsq-brlink">blog comments powered by <span class="logo-disqus">Disqus</span></a>

In my model I define Post, I define my short name like so:

  DISQUS_SHORTNAME = if Rails.env.development? 
                        "dev-shortname".freeze
                     else
                        "shortname".freeze
                     end

I can confirm the loading spinner is functioning but that is it. Am I missing something obvious? When I try to include only_path: false as a second option in my url_for call, I get an exception stating I have supplied to many arguments to the method. Otherwise my disqus just hangs.

回答1:

you should set this to make it work:

var disqus_developer = 1; // this would set it to developer mode

Reference: http://ray247.wordpress.com/2009/09/02/how-to-develop-with-disqus-on-localhost/



回答2:

None of the solutions above worked for me as of September 2013.

To get it to work I had to add localhost to the "Trusted Domains" list on this page:

http://[disqus_shortname].disqus.com/admin/settings/advanced/

and also use the "Universal Code" found below to embed it into my blog posts:

http://[disqus_shortname].disqus.com/admin/settings/universalcode/

And it works! :)



回答3:

Try setting disqus_url to match your registered site URL.

http://kenhirakawa.com/load-disqus-on-localhost/



回答4:

The recommend solution seems to be to register multiple shortnames aka sites. This worked for me. E.g., balloons and balloons-dev.

Make sure to modify the Javascript they give you to replace the shortname in the line which is below the comment about "do not modify", if want to dynamically set which site you're using based on your environment (e.g., "balloons" if not settings.DEBUG else "balloons-dev").

https://help.disqus.com/customer/portal/articles/1053796-best-practices-for-staging-development-and-preview-sites



回答5:

Disqus doesn't work on localhost as far as I know. It has always only worked on the production site for me. I believe it checks the hostname against the registered hostname.