Currently, I am working with Ruby on Rails 3.1.1 and using the jquery-rails 1.0.16 gem in my project. The issue I am facing involves utilizing a form with :remote => true
.
Within my view file, the form snippet looks like this:
<%= form_for(@user, :url => user_path(@user), :remote => true) do |f| %>
...
<%= f.submit "Update" %>
<% end %>
Upon clicking the Update
button, I noticed through the Firebug Console that two AJAX HTTP requests are triggered instead of one. This same issue persists across all forms in my application that have :remote => true
enabled.
Any insights on what might be causing this problem and how to resolve it?
Note: Upon inspecting the DOM, there are no duplicate HTML\CSS id
values present on the current page.
P.S. I: I have attempted troubleshooting by testing different browsers and clearing cache, but the issue remains unresolved.
P.S. II: The problem occurs specifically in development mode when running locally (on my machine). I have yet to test if it persists in production mode on a remote server.
UPDATE I
In my application.js
file, I initially had
//= require jquery
//= require jquery_ujs
//= require jquery-ui
Removing the line require jquery_ujs
seemed to temporarily fix the problem until executing the
bundle exec rake assets:precompile
command and restarting the server. More specifically, omitting the require jquery_ujs
line without running the bundle
command allowed normal functionality; however, running the command caused the AJAX form submission to stop working altogether.
Is it possible that the issue is linked to the fingerprinted files generated by the bundle
command?
UPDATE II
The JavaScript files structure in my filesystem appears as follows:
app/assets/javascripts/
app/assets/javascripts/application.js
lib/assets/javascripts/
vendor/assets/javascripts/
vendor/assets/javascripts/vendor.js
vendor/assets/javascripts/jquery_plugins/plugin1.js
vendor/assets/javascripts/jquery_plugins/plugin2.js
vendor/assets/javascripts/jquery_plugins/....js
Within my
app/assets/javascripts/application.js
file, the setup looks like this:
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//
//= require_tree .
//
//= require vendor
Meanwhile, in my
vendor/assets/javascripts/vendor.js
file, the content includes:
//= require_directory ./jquery_plugins
Executing the command below results in generating files inside the public/assets/
directory:
$ bundle exec rake assets:precompile
/<MY_USER_PATH>/.rvm/rubies/ruby-1.9.2-p290/bin/ruby /<MY_USER_PATH>/.rvm/gems/ruby-1.9.2-p290/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
/<MY_USER_PATH>/.rvm/rubies/ruby-1.9.2-p290/bin/ruby /U<MY_USER_PATH>/.rvm/gems/ruby-1.9.2-p290/bin/rake assets:precompile:nondigest RAILS_ENV=production RAILS_GROUPS=assets
Upon inspecting the HTML code of the page, the following scripts are loaded:
<script src="/assets/jquery.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery-ui.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_plugins/plugin1.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_plugins/plugin2.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_plugins/....js?body=1" type="text/javascript"></script>
<script src="/assets/vendor.js?body=1" type="text/javascript"></script>
<script src="/assets/application.js?body=1" type="text/javascript"></script>