Forum: Ruby on Rails 2 layouts per .rb page

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.
Scott S. (Guest)
on 2006-04-20 17:32
Hi,

Is this possible

ive got layout "loggedout_layout", :only => [:login, :logout]

but I also want to do somthing like
layout "loggedin_layout", :except => [:login, :logout]

When the second one is introduced it seems to cancel out the first
request, any suggestions how to get around this?

Scott
Peter E. (Guest)
on 2006-04-20 17:45
(Received via mailing list)
use this in your actions:

render [blah-blah], :layout => "bla"
Jean-François (Guest)
on 2006-04-20 17:54
(Received via mailing list)
Hello Scott,

> Is this possible
>
> ive got layout "loggedout_layout", :only => [:login, :logout]
>
> but I also want to do somthing like
> layout "loggedin_layout", :except => [:login, :logout]
>
> When the second one is introduced it seems to cancel out the first
> request, any suggestions how to get around this?

Tell me if it works :

class MyBeautifulController < ApplicationController
  layout :determine_layout

  # ...

  private
    def determine_layout
      if [:login, :logout].include?(controler.action_name)
        "loggedout_layout"
      else
        "loggedin_layout"
      end
   end
end

    -- Jean-François.
Scott S. (Guest)
on 2006-04-20 18:21
> Tell me if it works :

nice idea, but im gaining this error

NameError in AccountController#list

undefined local variable or method `controler' for
#<AccountController:0x38a7560>

code

layout :determine_layout

private
def determine_layout
  if [:login, :logout].include?(controler.action_name)
    "loggedout_layout"
  else
    "loggedin_layout"
  end
end
Alan F. (Guest)
on 2006-04-20 18:24
Scott S. wrote:
>> Tell me if it works :
>
> nice idea, but im gaining this error

>   if [:login, :logout].include?(controler.action_name)

2 'l's in controller.action_name

Alan

p.s. can't you specify :only *and* :except in the same layout line ?
Jean-François (Guest)
on 2006-04-20 18:28
(Received via mailing list)
2006/4/20, Scott S. <removed_email_address@domain.invalid>:
> > Tell me if it works :
>
> nice idea, but im gaining this error
>
> NameError in AccountController#list

sorry for the typo :

controller.action_name

instead of

controler.action_name

    -- Jean-François.
Scott S. (Guest)
on 2006-04-20 18:43
same problem again

undefined local variable or method `controller' for
#<AccountController:0x37da8e8>

RAILS_ROOT: ./script/../config/..
Application Trace | Framework Trace | Full Trace

#{RAILS_ROOT}/app/controllers/account_controller.rb:14:in
`determine_layout'


In response to
> can't you specify :only *and* :except in the same layout line ?

totally new to ror, but I couldnt find a way to define 2 templates on
one line
scott sherwood (Guest)
on 2006-04-20 23:37
I am still having problems with this, has anyone else got any
suggestions?
Jean-François (Guest)
on 2006-04-21 00:01
(Received via mailing list)
2006/4/20, scott sherwood <removed_email_address@domain.invalid>:
> I am still having problems with this, has anyone else got any
> suggestions?

change this line

 if [:login, :logout].include?(controler.action_name)

into :

if %w(login logout).include?(params[:action])

but it's not very nice to me.

     -- Jean-François.
This topic is locked and can not be replied to.