【问题标题】:Adding Disqus to rails blog将 Disqus 添加到 Rails 博客
【发布时间】:2017-01-18 02:10:54
【问题描述】:

我创建了一个博客,我想将 Disqus 集成到该站点中,以便人们可以发布 cmets。我按照 Disqus 网站上列出的步骤,一切正常,直到我开始设置配置变量的部分。 Disqus 停止加载并显示。我不确定我在这里做错了什么。

下面是我的代码:

<div id="disqus_thread"></div>
<script>
var disqus_config = function ()
    this.page.url = '<%= url_for([@post, {:only_path => false}]) %>';  // Replace PAGE_URL with your page's canonical URL variable
    this.page.identifier = '<%= @post.id %>'; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
    this.page.title = '<%= @post.title %>';
};

(function() { // DON'T EDIT BELOW THIS LINE
    var d = document, s = d.createElement('script');
    s.src = '//york-wang.disqus.com/embed.js';
    s.setAttribute('data-timestamp', +new Date());
    (d.head || d.body).appendChild(s);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>

【问题讨论】:

    标签: ruby-on-rails disqus


    【解决方案1】:

    经过几个小时的研究,我终于解决了这个问题。以下是我使用的代码:

    <div id="disqus_thread"></div>
    <script>
    
        var disqus_config = function () {
            s.src = '//YOURSHORTNAME.disqus.com/embed.js';  // IMPORTANT: Replace EXAMPLE with your forum shortname!
            this.page.url = '<%= url_for(@post) %>';
            this.page.identifier = '<%= @post.id %>';
            this.page.title = '<%= @post.title %>';
        };
    
    (function() { // DON'T EDIT BELOW THIS LINE
        var d = document, s = d.createElement('script');
        s.src = '//YOURSHORTNAME.disqus.com/embed.js';
        s.setAttribute('data-timestamp', +new Date());
        (d.head || d.body).appendChild(s);
    })();
    </script>
    <noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
    

    发现了 3 个问题: 1.我没有正确配置disqus连接的本地开发环境。 2. 我使用过时的命令将路径映射到我的论坛“短名称”。 3. this.page.url 的变量设置错误。修复代码并将所有内容上传到生产服务器后,Disqus 再次开始工作。

    【讨论】:

      猜你喜欢
      • 2015-12-10
      • 1970-01-01
      • 2023-04-11
      • 1970-01-01
      • 2021-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多