Turn off Rails' Layouts for AJAX Requests
December 20th, 2006
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”
Sorry, comments are closed for this article.
December 20th, 2006 at 09:40 PM
Hey Ryan,
Thanks…that is a great little bit of code!!!
Jeff
December 23rd, 2006 at 01:02 PM
Thanks for the snippet, this will be very useful!
— Vann
January 14th, 2007 at 02:40 AM
Today, i will can to sleep better. It’s great. Thank you.
-Tomás Lucas