Transparant redirect for jquery ajax requests in rails with status code 278

There is no perfect backwards compatible solution out there afaik, but this is getting me pretty close to where I want it to be.

  • instead of redirecting set a empty 278 response (made up status code) for xhr requests
  • tell jquery to redirect when receiving a 278 response
  • the success handlers are still executed / there is no way to stop them, but they can either just insert the blank reply or do a != '' check
// application.js
// when we get a fake redirect response, go there
// this will still execute success handlers, but hopefully the fail or are not ugly ...
  statusCode: {
    278: function(_,_,response){
      // using turbolinks to not lose back functionality
# some controller
redirect_to_with_xhr signup_path

# application_controller.rb
# ajax requests follow all redirects, so we have to improvise with a
# special code and header to not get placeholders replaced with full pages.
def redirect_to_with_xhr(path)
  if request.xhr?
    response.headers["X-278-redirect"] = path
    head 278
    redirect_to path

jQuery extension to ajax-ify selected links to stay inside a container

Make your links stay in a container, great for will_paginate / sorting headers and friends 🙂

// ajaxify all links that have “tab=my_container” in their href


  // make selected links in a container replace the container
  $.fn.ajaxifyContainer = function(selector){
    selector = selector || 'a';
    var $container = $(this);
    $(selector, $container).live('click', function(){
      $container.html("Loading ...").load($(this).attr("href"));
      return false;

jQuery .load extension to indicate loading and errors

  // show loading animation and errors inside the container that is being replaced
  $.fn.responsiveLoad = function(url, callback){
    var loading = 'Loading';
    var $container = $(this);
    $container.html(loading).load(url, function(response, status, xhr){
      if (status == "error") {
        $container.html("Error:" + xhr.status + " " + xhr.statusText);
      } else {
        if(callback) callback(response, status, xhr);

jQuery Plugin: A 1kb Simple Slider for Images + Description

I recently set out to find a good slideshow for our homepage, but most of them are monsters, with 20kb code, no thanks…
The simples/best solution i found was the s3Slider somewhat simple and looks good.

But after it started behaving silly (sliding to fast/slow, hanging on mouseover) I decided to fix it and discovered a pile of spaghetti. So here is my s3_slider rewrite download that is smaller(now ~1kb) / simpler / maintainable and more easy to setup! Demo of the new version