6
votes

I am facing a problem in production server. This is duplicate of another questions but all that questions-answers didn't work for me.

I used 'delete' method for 'link_to' tag:-

<%= link_to "Delete Campaign", campaign_path(campaign), :class => "btn btn-danger", :method => :delete, :confirm => 'Are you sure?'%>

When I click on "Delete Campaign" link, I am getting confirmation pop-up twice. This is happening on client's production environment only.

Using Ruby 1.9.2 and Rails 3.2.13.

In my gemfile, I used:-

gem 'jquery-rails'

In my application.js:-

//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require bootstrap-timepicker
//= require_tree ../../../vendor/assets/javascripts/

In my application.html.erb:-

<%= javascript_include_tag "application" %>
<%= javascript_include_tag "http://code.jquery.com/ui/1.10.2/jquery-ui.js" %>

When I searched about it, I found:-
1. config.assets.debug should be false in production.rb (It is false but not working)
2. There should be no public/assets directory (No such directory in app)
3. Run rake assets:clean on production (no effects)
4. These two line should be removed from application.js:-
//= require jquery
//= require jquery_ujs

Last one worked for me but after removing these lines, whole application been affected and all jquery event stopped working.

According to my knowledge either jquery is loading twice(but not more than one javascript_include_tag used) or there is a problem in "config.assets.compile" which is true in production.rb

I can't check it on my local and heroku too as it is working fine for both.

List of file in my vendor/assets/javascripts :-

  • bootstrap.js
  • bootstrap-datepicker.js
  • chai.js
  • jquery-cookie.js
  • mocha.js
  • moment.js
  • require.min.js
  • text.js
  • underscore-amd.js
2
Could you please list all the files in the tree ../../../vendor/assets/javascripts/?Fernando Diaz Garrido
@FernandoDiazGarrido : hi, list added in edited question, check aboveRohitPorwal
Just a suggestion, go to jquery-ui site, create a CUSTOM jquery-ui file with only the libraries that you're going to use, download it and add it to your assets. Rails will put it together in the application.js, one less resource to be loaded.Anezio Campos

2 Answers

1
votes

I encountered the same issue in a development environment (with Rails 3.2.13). I'm using the following gem versions (from Gemfile.lock): bootstrap-sass (2.3.1.0), sass-rails (3.2.6), jquery-rails (2.2.1). In app/assets/javascripts/application.js:

//= require jquery  
//= require jquery_ujs  
//= require bootstrap  
//= require_tree  

In application.html.erb:

<%= javascript_include_tag "application" %>  

In my erb template:

<%= button_to 'Delete', @card_type, method: :delete, form_class: 'destroy_button',  
data: { confirm: "Are you sure?" } %>  

It appears that the handler for input[data-confirm] is getting added twice, once by requiring jquery_ujs, and again by requiring bootstrap. I eliminated the double firing of the confirmation alert by not requiring jquery-ujs, but I'm hoping that someone else posts a more satisfactory solution.

1
votes

I'm using Rails 4 and none of the answers I found on SO worked for me except this one... I changed the line in application.html.erb:

<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> 

to

<%= javascript_include_tag 'application', 'data-turbolinks-eval' => false %>.

https://github.com/rails/turbolinks/issues/244