Forum: Ruby on Rails controller inheritance problem

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.
Ce953bec3af375ddc75e375233112b28?d=identicon&s=25 harper (Guest)
on 2006-12-28 10:14
Hi,

problems with inheritance (:: issues?)
i have the following two controllers:

application.rb
pages_contoller.rb

(PagesController < applicationController::Base )

in the applicationcontroller, i have some methods that implement the acl
system in my app (i.e,

  require "acl_system"
  class ApplicationController < ActionController::Base
    include ACLSystem
    etc....

which is spread across all of my controllers
(inlcuding the PageController < ApplicationController)

lately i've created a third controller, cms_controller.rb, which i want
to inherit all methods/functions from the above two.

so i did:

Class CmsController < PagesController < ApplicationController
    doesn't work
Class CmsController < PagesController::ApplicationController
    works only for methods in PagesController
Class CmsController < ApplicationController::PagesController
    works only for methods in ApplicationController

--- shouldn't

Class CmsController < PagesController

be enough? if Pages < Application, shouldn't Cms < Pages be enough to
inherit both controller methods?

i obviously am missing some important basic inheritance knowledge (at
least, i hope i am)...if someone could fill me in or point me out to
some reference, i would greatly appreciate it.

tia,

s
40db9e75b3f5899258e3bdc0c9210154?d=identicon&s=25 Conrad Taylor (Guest)
on 2006-12-28 10:45
(Received via mailing list)
Hi Tia, Ruby doesn't support multiple inheritance but it supports what
is called  a mixin module or simply a mixin.  Please reference
"Programming Ruby"  pages 118 - 120.

Good luck,

-Conrad
Ce953bec3af375ddc75e375233112b28?d=identicon&s=25 harper (Guest)
on 2006-12-31 15:42
Conrad Taylor wrote:
> Hi Tia, Ruby doesn't support multiple inheritance but it supports what
> is called  a mixin module or simply a mixin.  Please reference
> "Programming Ruby"  pages 118 - 120.
>
> Good luck,
>
> -Conrad

ok...

so i 'require' this module? it's not a module, it's a
ApplicationController / PagesController class, it's not a module
Something. i'm supposed to do require 'PagesController' and it will call
all the methods from the pages-controller automaticly? ...doesn't seem
to work just like that. . . unfortunately, i feel a little lost...
58c6efb8466b9f85155fe6aa9fc37fce?d=identicon&s=25 Chris T (Guest)
on 2006-12-31 17:52
(Received via mailing list)
harper wrote:
> ok...
>
> so i 'require' this module? it's not a module, it's a
> ApplicationController / PagesController class, it's not a module
> Something. i'm supposed to do require 'PagesController' and it will
> call all the methods from the pages-controller automaticly? ...doesn't
> seem to work just like that. . . unfortunately, i feel a little lost...
>
The point is, you're trying to inherit from two parents, which Ruby
doesn't support. The way around this -- in Ruby -- is, as Conrad said,
to use a module in which the methods you want are defined and then mix
this in.
This topic is locked and can not be replied to.