Missing rails.js with jquery-rails

I am new to Rails 3.1 and recently started a project. My gemfile contains jquery-rails:

gem 'jquery-rails' 

And indeed, I have confirmed that it is present (version 1.0.19) in my current gemset RVM (using gem list ).

I started getting forms with Ajax support and, reading various articles and posts from Googling, it seems that I should have a file called rails.js in my javascripts folder (I assume these are assets/javascripts/ and I use the asset pipeline for default).

My question actually includes two parts:

  • I could not find the rails.js file in my project even after bundle install , so I downloaded it from https://github.com/rails/jquery-ujs and put it in my assets/javascripts/ folder. Is this the right thing?

  • After enabling rails.js my Ajax form now submits three times. Upon further investigation, it seems that all my javascript (or jquery ???) get three times. When I click the destroy link for an object (the type generated by rails g scaffold something ), a confirmation pop-up window also appears three times. Removing the rails.js file also fixes this problem.

Any help or advice would be much appreciated ... I searched around Google and SO for many hours and haven’t gone anywhere. Thanks!

+6
source share
1 answer

jquery-rails serves jquery and jquery_ujs from inside the gem. You do not 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 you have javascript_include_tag 'application' in your layout.

+14
source

Source: https://habr.com/ru/post/904133/


All Articles