[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Newbie question about ActionController (I suppose) behavior

Jano Svitok

3/17/2007 2:00:00 PM

On 3/16/07, Paulo Schneider <paulo@flying-stuff.com> wrote:
> 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

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.