将Disqus添加到rails博客

时间:2016-09-09 21:16:00

标签: ruby-on-rails disqus

我创建了一个博客,我想将Disqus整合到网站中,以便人们发表评论。我按照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>

1 个答案:

答案 0 :(得分:2)

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

<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再次开始工作。

相关问题