Ask A Question

Notifications

You’re not receiving notifications from this thread.

Do I need rails-ujs and jquery_ujs?

Nick McNeany asked in Javascript

I'm bulding a rails 5.1.x app so no jQuery, but I'm usining Bootstrap so I added it in.

I was adding in //= require jquery and //= require jquery_ujs, then noticed that rails 5.1 now ships with //= require rails-ujs. My initial reaction is rails-ujs replaces the need for jquery_ujs so I don't need it.

My question is, will I run into any problems with jQuery if I do not include //= require jquery_ujs ?

Thanks for the help!

Nick

Reply

I did an episode on the new Rails UJS library. It replaces everything jquery_ujs does, but it just doesn't require jQuery: https://gorails.com/episodes/rails-ujs-primer

Feel free to add jquery in, but you won't need the jquery_ujs library. Everything will still function exactly the same as before, they just want to reduce dependencies.

Reply

My lazyness has been exposed! I didn't even bother to search the videos, haha!

Thanks for the help Chris! You're the man!

Reply

Hi, I am using the smart_listing gem and without requiring jquery_ujs I am getting some js errors. Probably smart_listing can be fixed. What i am trying to say is that there might be some compatibility issues with existing libraries.

P.S. so far I've removed rails_ujs and I'm only using jquery_ujs. So far no compat issues I see.

Update: actually if I enable both of them, then requests are processed twice instead of once. That means click form submit once but it is submitted twice. So one has to enable only one - rails-ujs or jquery_ujs.

HTH

Reply

@Alexander Kostadinov: yep, same result. you only need require rails_ujs, otherwise if you are doing any type of submission from client (for example), an alert will process twice.

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,140+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.