Question

I successfully deployed my app to Site5 - and as I started to play around on it, I realized that not all of the jQuery was working. Specifically, anything that involved grabbing information from Ruby Forms. I'm getting the following error:

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 

The script is as followed, and worked locally, on heroku, and on hostmonster so I'm confused as to why it is not working now. In the document:

<%= 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
    });
});

In Application.js:

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

In my layout file

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

In my Gemfile, under assets

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

Under Sources in 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 */
Was it helpful?

Solution

From the 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().

So live was deprecated way back in version 1.7 (November 2011) and removed completely in 1.9. You're using jQuery 1.9.1 so there is no more live. Since you say that it worked in some places but not others then you must be mixing jQuery versions, that's just a shortcut to pain and suffering so don't mix versions.

Update your jQuery code to use on instead of live and delegate. The live and delegate documentation show you how to convert live and delegate to on.

You should start paying attention to release notes and update your code: don't wait until features are removed, update your code as soon as anything is deprecated.

OTHER TIPS

Check if:

  • the gem jquery-rails is included in your assets group in your gemfile
  • jquery is included in your javascript manifest file
  • you compiled assets during deployment
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top