Never render a layout in response to xhrs

Posted by Horace Loeb on Stack Overflow See other posts from Stack Overflow or by Horace Loeb
Published on 2010-03-15T03:07:54Z Indexed on 2010/03/15 3:09 UTC
Read the original article Hit count: 355

Filed under:
|

Most of the time I don't want to render a layout when the request comes from AJAX. To this end I've been writing render :layout => !request.xhr? frequently in my controller actions.

How can I make this the default? I.e., I'd like to be able to write

def new
  Post.find(params[:id])
end

and have the functionality be

def show
  Post.find(params[:id])
  render :layout => !request.xhr?
end

(I'm fine manually specifying a layout in the rare cases in which I want to use one.)

© Stack Overflow or respective owner

Related posts about AJAX

Related posts about ruby-on-rails