# Can I call another controllers method from a controller?

**URL:** <https://www.ruby-forum.com/t/can-i-call-another-controllers-method-from-a-controller/147617>\
**Category:** Rails\
**Created:** [September 3, 2008, 5:31pm UTC](https://www.ruby-forum.com/t/can-i-call-another-controllers-method-from-a-controller/147617 "2008-09-03T17:31:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dino\_d](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b5ac83/32.png) [@dino\_d](https://www.ruby-forum.com/u/dino_d)\
**Post date:** [September 3, 2008, 5:31pm UTC](https://www.ruby-forum.com/t/can-i-call-another-controllers-method-from-a-controller/147617/1 "2008-09-03T17:31:59Z")

</div>

Is this possible? I don’t want to redirect, just want to utilize a  
method for convenience sake. I have a messages controller that just  
creates messages from user to user and there are many different kinds  
of messages, each generated from a different controller/view. Is it  
possible to call another controller’s method inside a controller? If  
not, is there another best practice to do this? I don’t want to put  
the functionality in the model because it cannot access helper  
methods, and I use current\_user from restful\_authentication.

Thanks for any help,  
Dino

---

<div class="post-metadata">

**Author:** ![dino\_d](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b5ac83/32.png) [@dino\_d](https://www.ruby-forum.com/u/dino_d)\
**Post date:** [September 3, 2008, 7:28pm UTC](https://www.ruby-forum.com/t/can-i-call-another-controllers-method-from-a-controller/147617/2 "2008-09-03T19:28:08Z")

</div>

yes it is posible,

if you want to use a method from the helper you have to add the helper  
to  
your controller  
include NameofthecontrollerHelper

the to access methods from the controller of the helper you need to call  
self.nameofthemethod

also if you want to access more than the CRUD  
(create,remove,update,delete)  
methods from the browser (common path ej new\_controller\_path) then yo  
have  
to add the methods to the routes:  
map.resources :nameofthecontroller, :collection=\>{:nameofthemethod =\>  
:any}  
#you can chanche the any for a specific action

hope it helps

On Wed, Sep 3, 2008 at 6:58 AM, dino d. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thanks for any help,  
> Dino
> 
> >

–  
Felipe V. Contesse  
IngenierÃ­a Civil Industrial UC

---

<div class="post-metadata">

**Author:** ![dino\_d](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b5ac83/32.png) [@dino\_d](https://www.ruby-forum.com/u/dino_d)\
**Post date:** [September 4, 2008, 2:05am UTC](https://www.ruby-forum.com/t/can-i-call-another-controllers-method-from-a-controller/147617/3 "2008-09-04T02:05:58Z")

</div>

dino d. wrote:

> Is this possible? I don’t want to redirect, just want to utilize a  
> method for convenience sake. I have a messages controller that just  
> creates messages from user to user and there are many different kinds  
> of messages, each generated from a different controller/view. Is it  
> possible to call another controller’s method inside a controller? If  
> not, is there another best practice to do this? I don’t want to put  
> the functionality in the model because it cannot access helper  
> methods, and I use current\_user from restful\_authentication.

If you move the method you wish to call into a controller that  
is a parent of both controllers, you can just call that method  
from the requested method. Add a render(:template) call to  
the destination method to ensure that the right view is rendered.

–  
Rails Wheels - Find Plugins, List & Sell Plugins -  
[http://railswheels.com](http://railswheels.com)

---

<div class="post-metadata">

**Author:** ![dino\_d](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b5ac83/32.png) [@dino\_d](https://www.ruby-forum.com/u/dino_d)\
**Post date:** [September 4, 2008, 3:40am UTC](https://www.ruby-forum.com/t/can-i-call-another-controllers-method-from-a-controller/147617/4 "2008-09-04T03:40:10Z")

</div>

Hi had this same problem to deal with, and I ended up having to copy  
the functionality into another set of controllers because they were  
logically too far from each other (they already had their own  
important inheritances). I never really dealt with it, but I will have  
to face up to it again soon as we’re modifying that part of the  
application. I’ve been toying with the idea of putting a lot of the  
duplicated functionality into a module in the lib directory and  
including that? Would be great to hear anyone’s war stories 🙂

Cheers,

Brendon

On Sep 4, 12:04 pm, Mark Reginald J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
