Nithin Bekal

Posts About Notes Slides

Don't use jquery-rails gem alongside rails-assets

21 May 2015

I’ve previously written about how much I like rails-assets for using bower packages with the Rails asset pipeline.

I started using rails-assets in one of my older projects which already had the jquery-rails gem. In order to not risk breaking anything, I decided to keep using that gem for jquery, and rails-assets for everything else.

Although this hasn’t caused any problems so far, I feel that this is a bad idea. In the project, I’m using jquery-textcomplete from rails-asset, which has jquery as one of its dependencies. Now I have two versions of jquery, and it’s confusing which version gets loaded by the //= require jquery line in the application.js manifest.

When starting a new project, I now remove the jquery-rails gem, and instead rely on rails-assets for all JS assets.

- gem 'jquery-rails'

+ source 'https://rails-assets.org' do
+   gem 'rails-assets-jquery'
+   gem 'rails-assets-jquery-ujs'
+   # ...
+ end

One thing to keep in mind is that you will also need to include jquery_ujs also from bower. This is required for Rails’ unobtrusive JS features like ajax forms and confirmation dialogs on delete links.

Hi, I’m Nithin Bekal, a software craftsman with over 7 years of experience in shipping web applications. I mostly use Ruby, but lately have also been exploring Elixir. Co-founder of CrowdStudio.in, and helping organize Rubyconf India. Tweet to me at @nithinbekal.