部署到Site5后jQuery无法正常工作

时间:2013-04-11 03:13:28

标签: jquery ruby-on-rails ruby ruby-on-rails-3 ruby-1.8.7

我成功将我的应用程序部署到Site5 - 当我开始玩它时,我意识到并非所有的jQuery都能正常工作。具体来说,涉及从Ruby Forms获取信息的任何事情。我收到以下错误:

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

Google Chrome中的来源:

/*!
 * 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 */

2 个答案:

答案 0 :(得分:2)

来自fine jQuery manual

  

.live(events,handler(eventObject)) 返回:jQuery
  弃用版本:1.7,删除:1.9
  [...]
  从jQuery 1.7开始,不推荐使用.live()方法。使用.on()附加事件处理程序。旧版jQuery的用户应优先使用.delegate() {。{1}}。

所以.live()在1.7版(2011年11月)中被弃用,并在1.9版中完全删除。您正在使用jQuery 1.9.1,因此不再有live。既然你说它在某些地方工作但不在其他地方工作那么你必须混合jQuery版本,这只是痛苦和痛苦的捷径,所以不要混合版本。

更新您的jQuery代码,使用on代替livelivelivedelegate文档说明了如何将delegatelive转换为delegate

您应该开始关注发行说明并更新代码:不要等到删除功能后,请在弃用任何内容后立即更新代码。

答案 1 :(得分:0)

检查是否:

  • gem jquery-rails包含在gemfile中的资产组中
  • jquery包含在您的javascript清单文件中
  • 您在部署期间编译了资产
相关问题