简体   繁体   中英

Double Javascript Dialog prompt

I have the following Ruby code:

<%= link_to "Install", install_game_path(game), :remote => true, :confirm => "Download local content for #{game.name}?", :title => "Install #{game.name}", :id => "game_#{game.id}_install_link" %>

This produces a line of code that looks like this: <a href="/games/install/3" data-confirm="Download local content for GAME 1?" data-remote="true" id="game_1_install_link" title="Install GAME 1">Install</a> <a href="/games/install/3" data-confirm="Download local content for GAME 1?" data-remote="true" id="game_1_install_link" title="Install GAME 1">Install</a>

However, in my development environment, it is producing two Javascript alert prompts. I don't have any Javascript/JQuery errors in Firefox. Why would this dialog appear twice (regardless of whether I click "OK" or "Cancel"?

Edit

<%= javascript_include_tag "application" %>
<%= javascript_include_tag 'http://github.com/cowboy/jquery-dotimeout/raw/v1.0/jquery.ba-dotimeout.min.js' %>

Produces this code:

<script src="/assets/jquery.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
<script src="/assets/games.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery.ba-dotimeout.min.js?body=1" type="text/javascript"></script>
<script src="/assets/pages.js?body=1" type="text/javascript"></script>
<script src="/assets/servers.js?body=1" type="text/javascript"></script>
<script src="/assets/application.js?body=1" type="text/javascript"></script>
<script src="http://github.com/cowboy/jquery-dotimeout/raw/v1.0/jquery.ba-dotimeout.min.js" type="text/javascript"></script>

The application.js file contains just the default contents:

//= require jquery
//= require jquery_ujs
//= require_tree .

Look like you have accidentally including two copies of rails.js. Can you check HEAD tag of the rendered page? Also if you are using using Rails 3.1 or later than check for jquery.js and jquery_ujs instead of rails.js. Somewhere you are calling js file twice.

Seems like the Rails handler for the "data-confirm" attribute has been assigned twice.

Any chance you have added two times you javascript tags (javascript_include_tag)?

Hi @andy it is because you pre-compiled assets in development so check in your public assets

folder it contain "application.js" which is already pre-compiled and rails development will

automatically picking compiled and individual js files.

Please remove public assets file in local if will fix your problem.


The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM