Copy the “universal code” of your Disqus account from your account’s admin page,
https://<your-account>.disqus.com/admin/install/platforms/universalcode/
.
The universal code is like below.
<div id="disqus_thread"></div>
<script>
/**
* RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS.
* LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT: https://disqus.com/admin/universalcode/#configuration-variables*/
/*
var disqus_config = function () {
this.page.url = PAGE_URL; // Replace PAGE_URL with your page's canonical URL variable
this.page.identifier = PAGE_IDENTIFIER; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
};
*/
(function() { // DON'T EDIT BELOW THIS LINE
var d = document, s = d.createElement('script');
s.src = 'https://<your-account>.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>
Paste it into where the Disqus comments block should display.
Set this.page.url
and this.page.identifier
and uncomment these lines to “avoid split threads and missing comments”.
For example, for this site they are set like below.
// tested in Rails 5
this.page.url = '<%= url_for host: "https://onefeed.xyz" %>';
this.page.identifier = '<%= @post.slug %>';
Update
If the Rails application is deployed behind a Nginx, where SSL/Https is enabled, and listening on an internal port like 3000.
The <%= url_for host: "https://onefeed.xyz" %>
above will generate values like http://onefeed.xyz:3000/posts/how-to-add-disqus-to-a-rails-application
.
To correct the port and the schema, use the code below.
this.page.url = '<%= url_for host: "onefeed.xyz", port: nil, protocol: "https" %>';
It generates URLs like https://onefeed.xyz/posts/how-to-add-disqus-to-a-rails-application
.
Check more in url_for API.