2013-04-11 87 views
0

我成功地將我的應用程序部署到了Site5--而且當我開始玩弄它時,我意識到並不是所有的jQuery都能正常工作。具體來說,任何涉及從Ruby表單獲取信息。我收到以下錯誤:jQuery在部署到Site5後不工作

Uncaught TypeError: Object [object Object] has no method 'live' 
Uncaught TypeError: Object [object Object] has no method 'live' 
(anonymous function) 
(anonymous function) 
ut.extend.globalEval 
ut.fn.extend.domManip 
ut.fn.extend.replaceWith 
(anonymous function) 
ut.event.dispatch 
y.handle 

腳本是緊隨其後,並在本地工作,在Heroku上,並在HostMonster的,所以我很困惑,爲什麼它不工作了。 在文件:

<%= form_for :team_design, :url => {:controller => "team_designs", :action => 'create'} do |f| %> 

    <%= f.label :style %> <%= f.select :style, [["Mens", "Mens"], ["Womens", "Womens"]], :include_blank=>'Select Style' %> 

...

$(document).ready(function() { 
    $('#target_div select#team_design_style').live('change', function() { 
     var suitStyle = $(this).val(); 
     switch (suitStyle) { 
        //all the different case possibilities 
    }); 
}); 

在application.js中:

//= require jquery 
//= require jquery_ujs 
//= require jquery-ui 
//= require_tree . 

在我的佈局文件

<head> 
    <title>scrubbed</title> 
    <%= stylesheet_link_tag "application", :media => "all" %> 
    <%= javascript_include_tag "application" %> 
    <%= csrf_meta_tags %> 
</head> 

在我的Gemfile,下資產

group :assets do 
    gem 'execjs' 
    gem 'therubyracer', :platforms => :ruby 
    gem 'johnson' 
    gem 'sass-rails', '~> 3.2.3' 
    gem 'coffee-rails', '~> 3.2.1' 

    # See https://github.com/sstephenson/execjs#readme for more supported runtimes 
    # gem 'therubyracer', :platforms => :ruby 
    gem 'jquery-rails' 
    gem 'uglifier', '>= 1.0.3' 
end 

在源在谷歌瀏覽器:

/*! 
* jQuery JavaScript Library v1.9.1 
* http://jquery.com/ 
* 
* Includes Sizzle.js 
* http://sizzlejs.com/ 
* 
* Copyright 2005, 2012 jQuery Foundation, Inc. and other contributors 
* Released under the MIT license 
* http://jquery.org/license 
* 
* Date: 2013-2-4 
*/ 
* Sizzle CSS Selector Engine 
* Copyright 2012 jQuery Foundation and other contributors 
* Released under the MIT license 
* http://sizzlejs.com/ 
*/ 
* http://jqueryui.com 
* Includes: jquery.ui.core.js, jquery.ui.widget.js, jquery.ui.mouse.js, jquery.ui.draggable.js, jquery.ui.droppable.js, jquery.ui.resizable.js, jquery.ui.selectable.js, jquery.ui.sortable.js, jquery.ui.effect.js, jquery.ui.accordion.js, jquery.ui.autocomplete.js, jquery.ui.button.js, jquery.ui.datepicker.js, jquery.ui.dialog.js, jquery.ui.effect-blind.js, jquery.ui.effect-bounce.js, jquery.ui.effect-clip.js, jquery.ui.effect-drop.js, jquery.ui.effect-explode.js, jquery.ui.effect-fade.js, jquery.ui.effect-fold.js, jquery.ui.effect-highlight.js, jquery.ui.effect-pulsate.js, jquery.ui.effect-scale.js, jquery.ui.effect-shake.js, jquery.ui.effect-slide.js, jquery.ui.effect-transfer.js, jquery.ui.menu.js, jquery.ui.position.js, jquery.ui.progressbar.js, jquery.ui.slider.js, jquery.ui.spinner.js, jquery.ui.tabs.js, jquery.ui.tooltip.js 
* Copyright 2012 jQuery Foundation and other contributors; Licensed MIT */ 
+0

您需要發佈所有標記。如果它很多,把它放在一個pastebin中。 – thealexbaron 2013-04-11 03:15:54

+0

什麼版本的jQuery正在使用,你從哪裏得到它? – 2013-04-11 03:16:25

+0

@ muistooshort我從jQuery.com使用v.1.9.1 – cadlac 2013-04-11 18:32:27

回答

2

fine jQuery manual

.live(events, handler(eventObject))Returns: jQuery
version deprecated: 1.7, removed: 1.9
[...]
As of jQuery 1.7, the .live() method is deprecated. Use .on() to attach event handlers. Users of older versions of jQuery should use .delegate() in preference to .live() .

所以live被棄用,早在1.7版本(2011年11月)和1.9完全去除。您正在使用jQuery 1.9.1,因此不再有live。既然你說它在某些地方有效,但不是其他地方,那麼你必須混合jQuery版本,這只是一個痛苦和痛苦的捷徑,所以不要混合使用版本。

更新您的jQuery代碼以使用on而不是livedelegatelivedelegate文檔向您顯示如何將livedelegate轉換爲on

您應該開始關注發佈說明並更新您的代碼:不要等到功能被刪除後,立即更新您的代碼。

+0

完美!答案有時很簡單.....哈哈 – cadlac 2013-04-11 19:35:07

0

檢查:

  • 寶石jQuery的軌道包含在您的資產組在你的Gemfile
  • jQuery是包含在您的JavaScript清單文件
  • 您在部署期間編譯了資產
+0

jquery-rails gem沒有被包含在資產下 - 我試着在那裏運行它,運行bundle instal和預編譯資產,但是沒有改變任何東西。在我的application.js中,我確實擁有所有// = require語句,並且使用rake資源預編譯資源:預編譯。我相信滿足那些,如果不讓我知道的話 – cadlac 2013-04-11 18:30:39