# Using layouts with RJS

**URL:** <https://www.ruby-forum.com/t/using-layouts-with-rjs/107082>\
**Category:** Rails\
**Created:** [June 17, 2007, 11:17pm UTC](https://www.ruby-forum.com/t/using-layouts-with-rjs/107082 "2007-06-17T23:17:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [June 17, 2007, 11:17pm UTC](https://www.ruby-forum.com/t/using-layouts-with-rjs/107082/1 "2007-06-17T23:17:38Z")

</div>

Here is a simple example that really has no real world use, but helps  
illustrate what I’m trying to do:

Let’s say you have a before filter that sets a variable @popup = true.  
In your RHTML layout if @popup is true you pop up a window. I want to do  
the same with RJS calls, if @popup is true pop up a window via  
javascript. The problem is that I have to include this check in EVERY  
RJS template I have. A layout for RJS template would be optimal. Is this  
possible?

I just want to use a layout with RJS template just as you would with  
RHTML template.

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [June 17, 2007, 11:33pm UTC](https://www.ruby-forum.com/t/using-layouts-with-rjs/107082/2 "2007-06-17T23:33:23Z")

</div>

Ben J. wrote:

> Here is a simple example that really has no real world use, but helps  
> illustrate what I’m trying to do:
> 
> Let’s say you have a before filter that sets a variable @popup = true.  
> In your RHTML layout if @popup is true you pop up a window. I want to do  
> the same with RJS calls, if @popup is true pop up a window via  
> javascript. The problem is that I have to include this check in EVERY  
> RJS template I have. A layout for RJS template would be optimal. Is this  
> possible?
> 
> I just want to use a layout with RJS template just as you would with  
> RHTML template.
> 
> Thanks for your help.

Just for other people viewing this, this worked…

@@exempt\_from\_layout = Set.new

I added that to the top of my applciation controller. Since  
ActionController initializes it with rjs. Then I put this in my  
determine layout method

def determine\_layout  
if request.xhr?  
“default.rjs”  
else  
“default.rhtml”  
end  
end

Kind of a hack, but its the only thing I could get to work.
