# Newbie question about ActionController (I suppose) behavior

**URL:** <https://www.ruby-forum.com/t/newbie-question-about-actioncontroller-i-suppose-behavior/89048>\
**Category:** Ruby\
**Created:** [March 16, 2007, 7:15pm UTC](https://www.ruby-forum.com/t/newbie-question-about-actioncontroller-i-suppose-behavior/89048 "2007-03-16T19:15:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cifroes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/53a042/32.png) [@cifroes](https://www.ruby-forum.com/u/cifroes)\
**Post date:** [March 16, 2007, 7:15pm UTC](https://www.ruby-forum.com/t/newbie-question-about-actioncontroller-i-suppose-behavior/89048/1 "2007-03-16T19:15:08Z")

</div>

Hi all,

I am pretty new at Ruby and, as such, I am full of questions and  
wonderments. The latest one, which I can’t figure it out is this: how  
does  
the “layout” method works (in Ruby terms) in a typical Rails controller,  
such as this

class MyController \< ApplicationController  
layout(“my\_layout”)  
end

I am a bit clueless, but I thought it worked as the “layout” method is  
defined somewhere along the inheritance hierarchy (perhaps at  
ActionController:Base). However, when I try to replicate it by creating  
a  
method on ApplicationController and making a similar call (also outside  
of a  
method scope), it doesn’t seem to work.

Thanks,  
Paulo

---

<div class="post-metadata">

**Author:** ![cifroes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/53a042/32.png) [@cifroes](https://www.ruby-forum.com/u/cifroes)\
**Post date:** [March 17, 2007, 3:01pm UTC](https://www.ruby-forum.com/t/newbie-question-about-actioncontroller-i-suppose-behavior/89048/2 "2007-03-17T15:01:06Z")

</div>

On 3/16/07, Paulo S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I am a bit clueless, but I thought it worked as the “layout” method is  
> defined somewhere along the inheritance hierarchy (perhaps at  
> ActionController:Base). However, when I try to replicate it by creating a  
> method on ApplicationController and making a similar call (also outside of a  
> method scope), it doesn’t seem to work.
> 
> Thanks,  
> Paulo

Hi, these are class methods, and you’ll find an explanation if you  
search for metaprogramming, or class methods or singleton methods

This is how it’s done:

class ApplicationController  
def self.layout(arg)  
#…  
end

layout  
end

Why and how is a longer story, but there are many good articles on the  
net.
