Determining Action in the Controller

Hi,

I am trying to select a layout for a page based on what action is called. ex.

if controller.action_name == ‘about’ layout “internal” else layout “home_static”

end

But I am receiving this error:

undefined local variable or method `controller' for HomeController:Class

Is there any way that I can do this? Is this even possible?

Thanks,

Jonathon

Hmm, not sure if this will work, but since the controller is the object and the "actions" are just methods then:

if self.respond_to?(about)   layout "internal" else   layout "home_static" end

I'm not sure whether layout can be called conditionally this way, but I *am* sure that "controller" is an instance variable, not a local variable. Try something like:

    if @controller.action_name == 'about'       layout "internal"     else       layout "home_static"     end

Craig

Hmm, interesting question, you could look at how Radiant or Typo or other apps do themes, e.g.

http://mattmccray.com/svn/rails/plugins/theme_support/ http://ragnarson.blogspot.com/2006/04/dynamic-templateroot-revisited.html http://ragnarson.blogspot.com/2006/03/dynamic-templateroot.html

http://ostracons.com/entry/259/full-plates

Found out the answer.

layout :choose_layout

private
def choose_layout
  if [ 'signup', 'login' ].include? action_name
    'login'
  else
    'admin'

  end
end

This works perfectly. From here: http://paulsturgess.co.uk/articles/show/41-how-to-specify-multiple-layouts-within-the-same-controller-in-ruby-on-rails