Forum: Ruby on Rails Using layouts with RJS

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ben J. (Guest)
on 2007-06-18 01:17
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. (Guest)
on 2007-06-18 01:33
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 topic is locked and can not be replied to.