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.
Fcf5e28e2e7ce245632a4a29896e6799?d=identicon&s=25 Scott Sherwood (Guest)
on 2006-04-20 15: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
36958dd94ca666a38483df282a5214d5?d=identicon&s=25 Peter Ertl (Guest)
on 2006-04-20 15:45
(Received via mailing list)
use this in your actions:

render [blah-blah], :layout => "bla"
13ea48f056b19349027d2f4a6921a46a?d=identicon&s=25 Jean-François (Guest)
on 2006-04-20 15: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.
Fcf5e28e2e7ce245632a4a29896e6799?d=identicon&s=25 Scott Sherwood (Guest)
on 2006-04-20 16: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
4daf0b71d5d9a3882e583c0e72eaf5dc?d=identicon&s=25 Alan Francis (Guest)
on 2006-04-20 16:24
Scott Sherwood 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 ?
13ea48f056b19349027d2f4a6921a46a?d=identicon&s=25 Jean-François (Guest)
on 2006-04-20 16:28
(Received via mailing list)
2006/4/20, Scott Sherwood <scott@urbandream.net>:
> > 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.
Fcf5e28e2e7ce245632a4a29896e6799?d=identicon&s=25 Scott Sherwood (Guest)
on 2006-04-20 16: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
Fcf5e28e2e7ce245632a4a29896e6799?d=identicon&s=25 scott sherwood (Guest)
on 2006-04-20 21:37
I am still having problems with this, has anyone else got any
suggestions?
13ea48f056b19349027d2f4a6921a46a?d=identicon&s=25 Jean-François (Guest)
on 2006-04-20 22:01
(Received via mailing list)
2006/4/20, scott sherwood <scott@urbandream.net>:
> 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.