Nithin Bekal Posts About

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 '' 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.

Nithin Bekal
Hi, I’m Nithin! This is my blog about programming. Ruby is my programming language of choice and the topic of most of my articles here, but I occasionally also write about Elixir, and sometimes about the books I read. I'm @nithinbekal on Twitter.