Integrate ConverseJS with Rails The Easy Way

If you ever needed to add chat to your Rails app, than you are probably familiar with the ConverseJS library, which is a great XMPP/Jabber compatible javascript client. But until today there was no asset-pipeline compatible gem that would add converse.js and converse.css to your app. As you probably know, adding external js and css files manually isn’t ideal, since it makes it harder to maintain and update versions.

Well, now there is:

Just add the following to your Gemfile:

gem 'conversejs-rails'

And add the following directive to your Javascript manifest file (application.js):

//= require converse

In case you receive weird javascript errors, that might be a sign that there are conflicts between your existing javascript files and converse. To solve this, try adding converse.js and converse.css in your layout file after all other javascripts, instead of adding a directive to manifest file, which doesn’t always guarantee order.

    <!-- all of your js and css files here --> 
    <!-- ..... --> 
    <%= stylesheet_link_tag "converse" %> 
    <%= javascript_include_tag "converse" %> 
  </head> ...

And that’s it.

Leave a Reply

Your email address will not be published. Required fields are marked *