Newbie question about ActionController (I suppose) behavior


#1

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


#2

On 3/16/07, Paulo S. 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.