Do you wonder, if implementing disqus on rails application is hard? I was wondering it as well when starting my rails blog, and here is the answer. Nothing is easier, if you use the proper gem, however in my case, choosing the gem wasn”t the biggest problem. Rather than asking ”How to implement disqus”, I needed to ask if ”do I really need it?”.

Why disqus, not comments, on Ruby on Rails Application?

I wondered if better is to keep independent comments on my blog, or add some social media to delegate managing discussions for each post. After few weeks of searching I made the decision. Take off comments and implement disqus on rails application.

Disqus is a platform designed to generate conversations for different topics. There is nothing more than discussions about everything, and you can find there a community interested with your content, whatever it is about. The community is already created, and all you need to do, is show them what you have to say about.

If I would like to stay with my previous (standard) solution of keeping my own comment engine on my blog, I would need to spend lot of time to generate community of people, who would subscribe my RSS channels, like my blog on facebook or observe on twitter. Then I would spend twice of this time to encourage them to comment on my blog. This requires to create lot of great content in short of time, and my free time is very limited by projects overload.

Few weeks ago I wrote about naming conventions in sass project and I spent on it so much time that I realized, that if anyone wants to be great developer, he won”t be able to blog a lot, less than fighting with SEO and generate traffic into the website. Oh, and if we talk about SEO – google gives as little attention as possible to comments section when their algorithm decides how to display your website in the search results. it”s often not worth of effort to implement own comment’s management, if you don”t suppose to make your blog your main earnings collector.

Even despite problems above I would created comments from scratch just because I’m ambitious guy, but then I found that there is more things to do. I would like to allow users to comment my posts as easily as possible, but this solution will expose my app for collecting spam from bots of any kind. To prevent that, I would need to implement a gem to check if the email passed as author”s email is valid, and maybe add akisment for using black list of IP addresses to filter valid comments from garbage. It”s fine and curious, but… I have no time for that.

Another thing is that collecting personal data (such emails) into database, is restricted by law in lot”s of countries, and without https protocol, which costs a bit, it’s not safe, so better is just to delegate responsibility to others, specialized with this part of business.

This is where disqus comes in.

Disqus gives you lot of prospectives, unreachable when you create comments from scratch:

  • gives you an access to large community
  • generates a traffic to your website
  • gives you complete comments management
  • gives you related posts and discussions, which links other articles between themselves
  • prevents your app from collecting spam
  • no law problems related to collecting users” personal data in you own database

When we talk about problems you could find with disqus on rails, there are a few:

  • less control over comments
  • you don’t collect emails ( for marketing purposes )

Probably you could find more, so please, add in comments.

The first position from problems list was ok for me, because comment control delivered by disqus is enough for my needs, and the second is completely unnecessary – I don’t need to collect emails from comments.

So for me it was natural choice.

Implementing Disqus on Rails application

As I said, implementing disqus in your Ruby on Rails application is extremely easy. There are few plugins to do the work, but I decided to use disqus_rails, developed by Sandric. This gem corresponds with Disqus API, so to make things work you will need to create an application on Disqus API website and get access keys to it.

Create new Disqus Application

First thing you need to do after generating the application, is to create your Disqus site used to promote content of your blog there. Only then you will be able to publish your discussions from blog comments directly in the disqus community.

Admin panel to add Disqus on rails

Implement disqus_rails Gem

disaqus_rails gem is the best one I found on Github but I had some problems with implementation at beginning. The disqus object organisation had been confusing a bit, because I understood ‘threads’ quite differently so far. However I tried to implement this plugin according to documentation, it didn”t work instantly. I have been confused what is going wrong, checked API keys, and every specific step of gem”s documentation without success. The solution I finally found on official Disqus documentation, however it also didn’t mention the problem directly.

The key is, that if you want to make things work, you need to push it to production environment. Disqus API checks, if hosted domain is the valid one, and none kind of localhost seems to be one. After pushing my changes to production, everything started working like a charm.

First add a gem to your gemfile:

Next, in your javascript manifest file, you need to import disqus_rails  file to allow loading disqus scripts in your website.

Almost everything is finished right now. Disqus API also requires two pieces of script included to your page. Both should be initialized once per page load. First script should be placed in head of the document, and other one, in the place when you want to create your discussions ( like in my case, at the bottom of every post ). Fortunately disqus_rails  allows us to use nice helpers for that, instead of typing any script from scratch.

And that’s it! Now the complete comment management, together with sharing posts, discussions, and mixing related articles is finished. Wasn’t it simple?

I’m so enjoyed with disqus on rails blog, that I also introduced it on my wordpress sites. It simplifies a lot, allows users to login once, and don’t use captcha to comment, which is obviously great.

But what about you? Do you prefer to use regular comments or social plugins to manage discussions? Please, comment below!

Shares
Share This