I'm new to Rails 3.1 and recently started a project. My Gemfile contains jquery-rails like so:
gem 'jquery-rails'
And indeed, I have verified that it's present (version 1.0.19) in my current RVM gemset (using gem list
).
I started to get into Ajax-enabled forms, and from reading various articles and posts from Googling, it appears that I'm supposed to have a file called rails.js
in my javascripts
folder (I assume this is assets/javascripts/
, and I am using the default asset pipeline).
My question actually involves two parts:
I couldn't find a rails.js
file in my project even after bundle install
, so I downloaded it from https://github.com/rails/jquery-ujs and placed it in my assets/javascripts/
folder. Is this the correct thing to do?
Upon including rails.js
, my Ajax form now submits three times. Upon further investigation it appears as if all my javascript (or jquery???) is getting called three times. When I click on the "destroy" link for an object (the kind generated when you rails g scaffold something
), the confirmation pop-up comes up three times as well. Removing the rails.js
file also removes this issue.
Any help or advice will be greatly appreciated... I've been searching around Google and SO for hours, and haven't gotten anywhere. Thanks!
jquery-rails serves jquery and jquery_ujs from inside the gem. You don't need to copy these files to assets/javascripts.
Make sure you have these two lines in javascripts/application.js:
//= require jquery
//= require jquery_ujs
And have javascript_include_tag 'application'
in your layout.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With