Using layouts with RJS

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.

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs