29

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.

rhodee
  • 1,227
  • 1
  • 14
  • 27

7 Answers7

17

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/

You knows who
  • 855
  • 8
  • 18
  • I am noticing that when setting the `disqus_url` and `disqus_identifier` the comment box breaks in dev mode. But I need them to work in production? Any ideas? – rhodee Feb 28 '12 at 19:21
  • I'm not sure,but when running on local, then Disqus server can not access your page , then many things can go wrong – You knows who Feb 29 '12 at 06:13
  • 21
    Although this was the case, i've just received confirmation from disqus tech support that `disqus_developer` has been deprecated. – Jose Browne Oct 17 '13 at 21:21
  • Right, it seems that setting `disqus_developer` variable doesn't help anymore. – devforfu Jan 05 '18 at 07:40
12

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! :)

rlueder
  • 310
  • 2
  • 6
  • 19
    It refuses localhost: "This domain name isn't valid. The domain should be formatted like 'example.com'" – Jiayi Hu Jul 23 '17 at 15:10
  • Guys, try to use other domain that points to `127.0.0.1` like `vcap.me` - see https://superuser.com/questions/1280827/why-does-the-registered-domain-name-localtest-me-resolve-to-127-0-0-1 – Tomasz Mularczyk Apr 19 '19 at 17:27
11

Try setting disqus_url to match your registered site URL.

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

Ken Hirakawa
  • 6,681
  • 10
  • 35
  • 49
  • This works perfectly in 2020 for loading on the local server. Match the registered url on disqus, for example 'http://kenhirakawa.com' (without the www) with the url + path to the page, if applicable, for example 'http://kenhirakawa.com/load-disqus-on-localhost' – Eduardo Matsuoka Dec 11 '20 at 19:23
1

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

John Lehmann
  • 6,887
  • 2
  • 51
  • 67
1

This might be old now, but I fixed it by keeping the URL empty on both my script and my Disqus setting

olayemii
  • 493
  • 1
  • 3
  • 14
1

For anyone in 2020 who faced this issue - I found that setting the shortname to my organization name in Disquss did the trick. And URL can be set to anything.

disqus_developer = 1 doesn't do anything.

Sergiy Kozachenko
  • 1,370
  • 10
  • 29
  • Still here in 2020, using organization name didn't help. Do you have the full snippet I can copy/paste to try? Thanks – Jon May 07 '20 at 08:29
  • @Jon Hi, in my case I was using react plugin `disqus-react`, the config was pretty simple: ``` const disqusConfig = { url: location.href, identifier: pageContext.slug || post.id, title: post.frontmatter.title, } ``` – Sergiy Kozachenko May 08 '20 at 13:29
-3

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.

airportyh
  • 19,441
  • 12
  • 54
  • 71