2013-05-01 43 views
0

我有以下Ruby代碼:雙的JavaScript對話框提示

<%= 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" %>

這將產生一行代碼,看起來像這樣: <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>

然而,在我的開發環境,它是生產兩個Javascript警報提示。我在Firefox中沒有任何Javascript/JQuery錯誤。爲什麼會出現這個對話框兩次(不論是否我點擊 「確定」 或 「取消」

編輯

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

產生以下代碼:

<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> 

中的application.js文件僅包含默認內容:

//= require jquery 
//= require jquery_ujs 
//= require_tree . 
+0

你能張貼的JavaScript部分? – DaveB 2013-05-01 18:59:46

+0

這個編輯是否包含你在問@DaveB的問題? – Andy 2013-05-01 20:54:50

回答

1

看起來你不小心包含了兩個rails.js副本。你能檢查呈現頁面的HEAD標籤嗎?此外,如果您使用的是Rails 3.1或更高版本,請檢查jquery.js和jquery_ujs而不是rails.js。某處你打電話給js文件兩次。

+0

我不小心將JQuery包含了兩次。我不再是,但仍然有同樣的問題。 – Andy 2013-05-01 20:55:55

+0

@Andy您是否還在更改後預編譯資產?我認爲它仍然會採用以前版本的頁面。預編譯:bundle exec rake資源:預編譯 – 2013-05-01 21:03:09

0

看起來像「數據確認」屬性的Rails處理程序已分配兩次。

任何機會你添加了兩次你的javascript標籤(javascript_include_tag)?

+0

我在原始問題中添加了'javascript_include_tag'代碼。 – Andy 2013-05-01 20:56:33

0

嗨@andy那是因爲你預編譯的開發資產在你的公共資產,以便檢查

文件夾包含它「的application.js」這已經是預編譯,並自動Rails開發將

選擇編譯和個人js文件。

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