Ruby on Rails problems & solutions - Nov 26, 2010

November 27, 2010

jQuery ajax requests & Firebug console logging

Coordinating development with our “front-end” person, we ran into an interesting problem today.  I really haven’t developed an exclusively ajax app before, so the full range of front-end Javascript interactions was new to me.  Ran into a problem, with jQuery and a response to a remote form submit.  Specifically, on the error handler.

Some strangeness I found when I looked for answer:

But, that wasn’t it.  The simple fact is, Firebug failed us, in 2 different ways (Mac & Linux).  It seems trying to dump the entire xhr contents on the error handler fails when you try to access  Fails silently and mysteriously on Linux, and fails in ways that sometime block the console log completely on the Mac.  Frustrating.  Note that your status will appear in xhr.status, and your errors in xhr.responseText, if your action response looks like:

format.js  { render :json => @job.errors, :status => :unprocessable_entity }

And your failure binding looks like:

f.bind(‘ajax:failure’, jobSavedFailure);

var jobSavedFailure = function(event, xhr, status, error) {…}

Will_paginate with Rails 3

Couple of things about using will_paginate with Rails 3.  

Remote pagination links (awesome):

And, as long as you are using the rails3 branch, scopes should “just work” (Model.scope.paginate), and you won’t have to go thru contortions like this link suggests:

Resizable table columns

Of course, when I suggested limiting the number of columns in our table, due to width constraints, our project manager decided he wanted resizable columns instead.  If you are using jQuery, I suggest this plugin:

} else { $('#cookie-notice').show(); } $('#cookie-notice-accept').click(function() { createCookie('cookie-notice-dismissed','true',365); // Change from 1 month to 1 year. $('#cookie-notice').hide(); });