Here’s a quick snippet for your ApplicationController:

layout proc{ |c| c.request.xhr? ? false : "application" }

HTTP requests using get and post will be processed normally, but AJAX requests will be rendered with no layout. This saves you from having to put render :layout => false every time you do an AJAX request.


3 Responses to “Turn off Rails' Layouts for AJAX Requests”

  1. Jeff Berg Says:

    Hey Ryan,

    Thanks…that is a great little bit of code!!!

    Jeff

  2. Vann Says:

    Thanks for the snippet, this will be very useful!

    — Vann

  3. Tomás Lucas Says:

    Today, i will can to sleep better. It’s great. Thank you.

    -Tomás Lucas

Sorry, comments are closed for this article.