0

I like to include bower, node packages in my Rails app using Rails Assets:

source 'https://rails-assets.org' do
  gem 'rails-assets-colorbox'
end

# ...

gem 'jquery-rails'

Now when I did run bundle install I got the following output:

...
Using pg 0.18.1
Installing rails-assets-jquery 2.1.3
Installing rails-assets-colorbox 1.6.0
Using ruby-graphviz 1.0.9
...

Now I am already using the jquery-rails plugin which is obviously a wrapper of jquery but which, I believe, does more advanced rails-related stuff too.

So now I seem to have two versions of jquery in my Rails app which is not ideal.

My questions is now whether I can get rid of jquery-rails and just include rails-assets-jquery in my Gemfile

1 Answer 1

1

If you are not using jquery-ujs, you may not use the gem jquery-rails at all.

jquery-ujs wires event handlers to eligible DOM elements to provide enhanced functionality. In most cases, the eligible DOM elements are identified by HTML5 data attributes.

For example, If you have a HTML form, and if you want to submit your HTML form in a Ajax way (instead of a pageload), you'd have to add :remote=>true attribute in to your form_for. Your controller, now can respond to the ajax request, that could be a HTML Embed. This would help you to improve user experience, while still keeping the client-side js light.

jquery-ujs would fire events that you could handle, for example ajax:success ajax:error.

If you are new to rails, try going to this walk through.

  1. https://robots.thoughtbot.com/a-tour-of-rails-jquery-ujs
  2. http://www.alfajango.com/blog/rails-3-remote-links-and-forms/

You may also prefer to include jQuery using CDN, if you only want to use jQuery but not jquery-ujs. Its more efficient.

Sign up to request clarification or add additional context in comments.

1 Comment

can you explain why jquery-ujs makes the difference?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.