views:

223

answers:

2

My controller renders regular html, mobile_fu, and javascript as such:

respond_to do |format|
  format.html {
    render :action => "full", :layout => "application" and return
  }
  format.mobile {
    render :action => "full", :layout => "application" and return
  }
  format.js {
    render :partial => "content", :layout => false and return
  }
end

Regular html renders fine, using AJAX from the html version of the site works fine, but using AJAX on the mobile browser seems to always render the format.mobile block. I'm using jQuery when binding it to the click event of a button, and my testing on the iPhone always ends up rendering the format.mobile block above..

$.ajax({
          beforeSend      : function(request) { request.setRequestHeader("Accept", "text/javascript"); },
          success         : function(response) {
            $("#content").append(response);
          },
          type            : 'GET',
          url             : url, //set somewhere else
          data            : data //set somewhere else
      });

Is jQuery not catching the click event (iPhone quirk?) or is mobile_fu taking charge and being a little overbearing here? Anyone already tackled this or see what I'm missing?

+2  A: 

Looking at the code for mobile_fu shows that any mobile request coming in will be set to mobile. Changing line 73 to something like this might work:

if is_mobile_device? && !request.xhr?
Andy Gaskell
Thanks Andy, simple straight forward patch there, and it works!
revgum
A: 

Just in case someone else finds this, if you have different javascript for mobile devices, you can do:

format.mobile {render :content_type => "application/javascript"}

(put your js in action.mobile.rjs)

woahdae