【问题标题】:Disqus comments fails to load on localhost?Disqus 评论无法在本地主机上加载?
【发布时间】:2012-02-28 03:00:44
【问题描述】:

我想使用通用代码,但在完成最基本的功能时遇到了困难。

我想为 test 创建一个短名称,并为我的 deployment 创建一个短名称,这是我在 Disqus 管理面板中完成的。

这是我的表演动作中的 disqus 代码:

# 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>

在我的模型中,我定义了Post,我这样定义了我的简称:

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

我可以确认加载微调器正在运行,但仅此而已。我错过了一些明显的东西吗?当我尝试在我的 url_for 调用中包含 only_path: false 作为第二个选项时,我收到一个异常,指出我已向该方法提供了许多参数。否则我的 disqus 就会挂起。

【问题讨论】:

    标签: javascript ruby-on-rails disqus


    【解决方案1】:

    您应该设置它以使其工作:

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

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

    【讨论】:

    • 我注意到在设置 disqus_urldisqus_identifier 时,评论框会在开发模式下中断。但我需要他们在生产中工作吗?有什么想法吗?
    • 我不确定,但是在本地运行时,Disqus服务器无法访问您的页面,那么很多事情都会出错
    • 虽然是这样,但我刚刚收到 disqus 技术支持的确认,disqus_developer 已被弃用。
    • 对,设置disqus_developer 变量好像没有用了。
    【解决方案2】:

    截至 2013 年 9 月,上述解决方案均不适合我。

    为了让它工作,我必须将 localhost 添加到此页面上的“受信任的域”列表中:

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

    并使用下面的“通用代码”将其嵌入到我的博客文章中:

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

    而且它有效! :)

    【讨论】:

    • 拒绝本地主机:“此域名无效。域名格式应类似于'example.com'”
    • 伙计们,尝试使用其他指向127.0.0.1 的域,例如vcap.me - 请参阅superuser.com/questions/1280827/…
    【解决方案3】:

    尝试设置disqus_url 以匹配您注册的网站网址。

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

    【讨论】:

    【解决方案4】:

    推荐的解决方案似乎是注册多个短名称,也就是网站。这对我有用。例如,balloonsballoons-dev

    如果想根据您的环境动态设置您正在使用的网站(例如,@ 987654324@).

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

    【讨论】:

      【解决方案5】:

      这现在可能已经过时了,但我通过在我的脚本和我的 Disqus 设置中保持 URL 为空来修复它

      【讨论】:

        【解决方案6】:

        对于 2020 年遇到此问题的任何人 - 我发现在 Disquss 中将短名称设置为我的组织名称可以解决问题。并且 URL 可以设置为任何内容。

        disqus_developer = 1 什么都不做。

        【讨论】:

        • 2020 年仍然在这里,使用组织名称没有帮助。你有完整的 sn-p 我可以复制/粘贴试试吗?谢谢
        • @Jon 嗨,在我的例子中,我使用的是 react 插件disqus-react,配置非常简单:``` const disqusConfig = { url: location.href, identifier: pageContext.slug || post.id,标题:post.frontmatter.title,} ``
        【解决方案7】:

        据我所知,Disqus 在本地主机上不起作用。它一直只适用于我的生产现场。我相信它会根据注册的主机名检查主机名。

        【讨论】:

          猜你喜欢
          • 2014-09-23
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-12-26
          • 2011-08-16
          • 2022-08-14
          相关资源
          最近更新 更多