# Calling action from one controller to second

**URL:** <https://www.ruby-forum.com/t/calling-action-from-one-controller-to-second/131454>\
**Category:** Rails\
**Created:** [March 10, 2008, 9:00am UTC](https://www.ruby-forum.com/t/calling-action-from-one-controller-to-second/131454 "2008-03-10T09:00:32Z")\
**Posts on this page:** 3\
**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:** [March 10, 2008, 9:00am UTC](https://www.ruby-forum.com/t/calling-action-from-one-controller-to-second/131454/1 "2008-03-10T09:00:32Z")

</div>

question:

class ControllerAthing  
def a\_method  
end  
end

class ControllerBthing  
def b\_method  
ControllerAthing::a\_method #this is what i want to do  
end  
end

but when i do that i can an error:  
undefined method `a\_method’ for ControllerAthing:Class

thanks …

---

<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:** [March 10, 2008, 9:28am UTC](https://www.ruby-forum.com/t/calling-action-from-one-controller-to-second/131454/2 "2008-03-10T09:28:14Z")

</div>

Shai R. wrote:

> class ControllerAthing  
> def a\_method  
> end  
> end
> 
> class ControllerBthing  
> def b\_method  
> ControllerAthing::a\_method #this is what i want to do  
> end  
> end
> 
> but when i do that i can an error:  
> undefined method `a\_method’ for ControllerAthing:Class

Because you’re treating #a\_method as a class method when it is an  
instance method.

Put #a\_method into app/controllers/application.rb instead. This file  
defines the class ApplicationController which your other controllers  
inherit from, so this will make the method available in all controllers.

---

<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:** [March 11, 2008, 4:24am UTC](https://www.ruby-forum.com/t/calling-action-from-one-controller-to-second/131454/3 "2008-03-11T04:24:35Z")

</div>

Mark is right and the other option you have is use mixin ie create a  
module, put your a\_method in it and include that module in both  
controller classes. This will make your a\_method available in both  
controllers or in any controller in which you include that module.

Cheers

On Mar 10, 8:00 am, Shai R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
