0

I've recently started using Rails-assets.org and noticed that, if a particular asset has jQuery as a dependancy, it installs a version from Bower when bundling. This duplicates the jQuery package in a Rails app (given the use of the default 'jquery-rails' gem).

I'd be happy to keep only either version of jQuery but I've found two problems when trying to do so.

  1. If I exclude 'jquery-rails' gem form my app I won't be able to run 'jquery_ujs' which is packed together with the 'jquery-rails'. I haven't find a way to keep only 'jquery_ujs'. Is that possible?

  2. It'd probably be better to exclude the jQuery dependancy when installing a gem from rails-assets.org so I could keep using the default jQuery gem in Rails. I've googled this without success. Is this possible?

I was also wondering if it would be a problem if I leave both jQuery packages installed. Which one of those will be chosen by rails asset pipeline? I've tried and I haven't got any errors, but it doesn't sound like the best idea.

It'd be great if you can point me towards the right direction or advice on best practice. Thanks

alopez02
  • 1,524
  • 2
  • 17
  • 36
  • 2
    You could install jquery_ujs through bower since it has a bower.json manifest. Not sure if this is an issue in the first place though. Using `gem "rails-assets-jquery-ujs"` would cause rails-assets to load the dependency though bower. I would just check if multiple versions of jquery are actually present on the page. If they are just there in the gems don't worry about it. – max Jan 19 '17 at 01:45
  • I didn't know there was a jQuery-ujs at rails-assets. However, maybe you are right. I left both versions of jQuery and after checking in inspector > sources there appear only to be one jQuery. Everything seems to work fine as well with both gems. So maybe is not a big deal. – alopez02 Jan 19 '17 at 05:53
  • If you read the docs on rails-assets it says that it can be used to import any bower component. [jquery_ujs](https://github.com/rails/jquery-ujs) is a gem, bower component and node package all in one. – max Jan 19 '17 at 06:54
  • I see. I suppose I'll do that if I run across any problems having those 2 gems. Thanks for your help mate. – alopez02 Jan 19 '17 at 08:06

0 Answers0