Sign in through GitHub

Please read for an updated status on RailsCasts:

Learn more or hide this

Mizpah's Profile

GitHub User: Mizpah

Comments by Mizpah

Avatar

Firstly am new to this so if anything is wrong, apologies and please correct it!

If you use application.js as is written in the example, no ajax will happen... (it would of worked when it was first written).

This is due to the 'live' event being replced with 'on' in the current version of jquery.

However live, used to stay bound to all future nodes. 'on' by default does not.

Thus if you just change 'live' to 'on' it will work once (for one click per page), and then fallback to non ajax.

We also need change how the line is written to include the nodes to stay bound to:

  • $(document).on("click","#game_classes th a, #game_classes .pagination a", function() {* would replace the line used in the original:

I also believe we now need the lines in application.js that load other documents (// = require somthing).

Thus my complete application.js looks like this:

ruby...
//= require jquery
//= require jquery_ujs
//= require_tree .
$(function() {
$(document).on("click","#game_classes th a, #game_classes .pagination a", function() {
$.getScript(this.href);
return false;
});
$("#game_classes_search input").keyup(function() {
$.get($("#game_classes_search").attr("action"), $("#game_classes_search").serialize(), null, "script");
return false;
});
});
...

Hopefully this helps someone!

ps: this applied on 25/02/2013, rails 3.2
pps: this can also be done with coffeescript , in the relevant file! (products.js.coffee in the example given)