Forum: Ruby Newbie question about ActionController (I suppose) behavior

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.
44cdbdd41032fe6b2d5a31ce2ff7c103?d=identicon&s=25 Paulo Schneider (Guest)
on 2007-03-16 19:15
(Received via mailing list)
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
97550977337c9f0a0e1a9553e55bfaa0?d=identicon&s=25 Jan Svitok (Guest)
on 2007-03-17 15:01
(Received via mailing list)
On 3/16/07, Paulo Schneider <paulo@flying-stuff.com> 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.
This topic is locked and can not be replied to.