Integrating AddThis with Rails 4

Integrating AddThis with Rails 4

___

In this short tutorial, I will explain how I got AddThis working with turbolinks in a rails 4 application

So I recently signed up for Addthis and added their share tools to my tutorials section of this site. I had AddThis working normally on a full page load but navigation to a different page caused the links not to show up as I was using turbolinks gem which makes following links in a rails application feel amazingly faster.

I spent alot of time searching on Google and Stackoverflow for a solution but most of them din't work for me. I stumbled upon a solution that worked for me on the turbolinks issues page on Github. I expect this to not be a terribly popular article, but if I ever need to set this stuff up myself in the future, then I’ll have it written down somewhere at least!

Create a javascript file in your javascripts folder call it addthis.js and add the following code.

Remember to require the file in your manifest javascript file

addthis.js

Loading Gist

Most of other solutions I found din't work because it looks like AddThis was setting tens of properties on window and checks for some of those before reloading, So I decided to go with this solution. Hope it helps! Thank you for reading


2 Comments

___

9c05736f74c2008b27f0900db5253bd7f96159db

jhorsch

02 Jul 14

Thanks for this post. I have spent so many hours trying to get this to work. Ive had the exact same issue. It is working in my development but when I post to heroku the sharing buttons disappear. So confusing. Any ideas as to why? I do use a rack-zippy gem to serve the compressed js and css files, but that shouldn't effect anything as my other other javascript plugins work.

9c05736f74c2008b27f0900db5253bd7f96159db

jhorsch

02 Jul 14

Ahhh. I have to use https instead of http in the url. Thanks so much for this post! https://www.luminoto.com/ph...

Latest Tutorials

___

Private Inbox System in Rails with Mailboxer New

Introduction It's been quite a while since my last tutorial and since then I've recieved alot of requests by email to implement a private messaging system ...

Ajax Sortable Lists Rails 4

With me, is a simple to-do list application where users can create dummy to-do lists and displays them in card-like form just like in Trello. We want to e...

Managing ENV variables in Rails

Often when developing Rails applications, you will find a need to setup a couple of environment variables to store secure information such as passwords, a...

Gmail Like Chat Application in Ruby on Rails

Introduction We are all fond of the Gmail and Facebook inline chat modules. About a week ago, I came across a tutorial on how to replicate hangouts chat...

Fast Autocomplete Search Terms - Rails

Introduction In many cases you find that you need to introduce a global search in your rails application i.e. search multiple models at a go using one form...

Load more scroll top