RoR中的Disqus动态变量:已解决

时间:2019-04-04 18:15:11

标签: ruby-on-rails disqus

通过RoR博客网站教程进行学习,但是我在添加Disqus方面陷入了困境。它不喜欢我如何编写动态变量。对于所有这一切仍然很新。

<div id="disqus_thread"></div>
<script>

var disqus_config = function () {
this.page.url = '<%= url_for([@post, {only_path: false}]) %>';
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 = 'https://myshortname.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>

更新: 我注意到我的网址显示不正确。检查显示的disqus javascript:

var disqus_config = function () {
this.page.url = '/posts/5'; //This should be a complete url
this.page.identifier = '5';
this.page.title = 'Article 5';
};

已解决: 我猜在Rails 5中,URL语法是不同的。

this.page.url = '<%= url_for(only_path: false) %>';

1 个答案:

答案 0 :(得分:0)

this.page.url = '<%= url_for(only_path: false) %>';