# Controller inheritance problem

**URL:** <https://www.ruby-forum.com/t/controller-inheritance-problem/80528>\
**Category:** Rails\
**Created:** [December 28, 2006, 10:14am UTC](https://www.ruby-forum.com/t/controller-inheritance-problem/80528 "2006-12-28T10:14:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![harper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5ac83/32.png) [@harper](https://www.ruby-forum.com/u/harper)\
**Post date:** [December 28, 2006, 10:14am UTC](https://www.ruby-forum.com/t/controller-inheritance-problem/80528/1 "2006-12-28T10:14:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![harper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5ac83/32.png) [@harper](https://www.ruby-forum.com/u/harper)\
**Post date:** [December 31, 2006, 3:42pm UTC](https://www.ruby-forum.com/t/controller-inheritance-problem/80528/2 "2006-12-31T15:42:59Z")

</div>

Conrad T. 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…

---

<div class="post-metadata">

**Author:** ![harper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5ac83/32.png) [@harper](https://www.ruby-forum.com/u/harper)\
**Post date:** [December 28, 2006, 10:45am UTC](https://www.ruby-forum.com/t/controller-inheritance-problem/80528/3 "2006-12-28T10:45:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![harper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5ac83/32.png) [@harper](https://www.ruby-forum.com/u/harper)\
**Post date:** [December 31, 2006, 5:52pm UTC](https://www.ruby-forum.com/t/controller-inheritance-problem/80528/4 "2006-12-31T17:52:59Z")

</div>

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.
