# Action in a action from an other controller

**URL:** <https://www.ruby-forum.com/t/action-in-a-action-from-an-other-controller/118961>\
**Category:** Rails\
**Created:** [November 1, 2007, 7:17pm UTC](https://www.ruby-forum.com/t/action-in-a-action-from-an-other-controller/118961 "2007-11-01T19:17:11Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![heldopslippers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b9bd4f/32.png) [@heldopslippers](https://www.ruby-forum.com/u/heldopslippers)\
**Post date:** [November 1, 2007, 7:17pm UTC](https://www.ruby-forum.com/t/action-in-a-action-from-an-other-controller/118961/1 "2007-11-01T19:17:11Z")

</div>

he…

I have an action and in this action I want to call an other action  
for example list in controller article…

I now how to do this if the action you want to call is in the same  
controller:

def index  
list  
end

but what if the action is in a other controller?  
article/list doesn’t work

hope somebody can help me …

---

<div class="post-metadata">

**Author:** ![heldopslippers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b9bd4f/32.png) [@heldopslippers](https://www.ruby-forum.com/u/heldopslippers)\
**Post date:** [November 1, 2007, 7:20pm UTC](https://www.ruby-forum.com/t/action-in-a-action-from-an-other-controller/118961/2 "2007-11-01T19:20:40Z")

</div>

Nice … I also want to know this…

On 01/11/2007, Heldop S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–

Arun A.

Sent from BlackBerry(R) on Hutch

---

<div class="post-metadata">

**Author:** ![heldopslippers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b9bd4f/32.png) [@heldopslippers](https://www.ruby-forum.com/u/heldopslippers)\
**Post date:** [November 1, 2007, 8:19pm UTC](https://www.ruby-forum.com/t/action-in-a-action-from-an-other-controller/118961/3 "2007-11-01T20:19:14Z")

</div>

On 1 Nov 2007, at 18:19, Arun A. wrote:

> I now how to do this if the action you want to call is in the same  
> controller:
> 
> def index  
> list  
> end
> 
> but what if the action is in a other controller?  
> article/list doesn’t work

You can’t. Why do you want to do this? This probably means that this  
code you are trying to call should either be part of one of your  
models or in a module you can include in both controllers.

Fred

---

<div class="post-metadata">

**Author:** ![heldopslippers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b9bd4f/32.png) [@heldopslippers](https://www.ruby-forum.com/u/heldopslippers)\
**Post date:** [November 1, 2007, 10:25pm UTC](https://www.ruby-forum.com/t/action-in-a-action-from-an-other-controller/118961/4 "2007-11-01T22:25:40Z")

</div>

On 1 Nov 2007, at 19:26, Heldop S. wrote:

> > 
> 
> I have an action index where I call for example the action article.
> 
> for example to do this:  
> if bla than  
> article  
> else  
> login  
> end

You should redirect them to the login page if they need to be logged in

Fred

---

<div class="post-metadata">

**Author:** ![heldopslippers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b9bd4f/32.png) [@heldopslippers](https://www.ruby-forum.com/u/heldopslippers)\
**Post date:** [November 1, 2007, 8:26pm UTC](https://www.ruby-forum.com/t/action-in-a-action-from-an-other-controller/118961/5 "2007-11-01T20:26:40Z")

</div>

Frederick C. wrote:

> On 1 Nov 2007, at 18:19, Arun A. wrote:
> 
> > I now how to do this if the action you want to call is in the same  
> > controller:
> > 
> > def index  
> > list  
> > end
> > 
> > but what if the action is in a other controller?  
> > article/list doesn’t work
> 
> You can’t. Why do you want to do this? This probably means that this  
> code you are trying to call should either be part of one of your  
> models or in a module you can include in both controllers.
> 
> Fred

I have an action index where I call for example the action article.

for example to do this:  
if bla than  
article  
else  
login  
end

It would be nise to have that in seperated controllers so that  
everything is organised … ☹

thanxs for the replay

---

<div class="post-metadata">

**Author:** ![heldopslippers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b9bd4f/32.png) [@heldopslippers](https://www.ruby-forum.com/u/heldopslippers)\
**Post date:** [November 1, 2007, 11:27pm UTC](https://www.ruby-forum.com/t/action-in-a-action-from-an-other-controller/118961/6 "2007-11-01T23:27:07Z")

</div>

Frederick C. wrote:

> On 1 Nov 2007, at 19:26, Heldop S. wrote:
> 
> > > 
> > 
> > I have an action index where I call for example the action article.
> > 
> > for example to do this:  
> > if bla than  
> > article  
> > else  
> > login  
> > end
> 
> You should redirect them to the login page if they need to be logged in
> 
> Fred

wel … yes I now…

it was just an example (and not a realy good one ) … here is my  
problem:

I have a layout page where a menu and articles are loaded … when you  
start the site you are in the action index (in application)… the index  
will call the actions menu, articles and login (this is in the footer)  
(and more if nessecery).

I have now all the actions in the application but I would like to have  
them in other controllers. beceause it is more manageble… but I  
understand that is not possible.

---

<div class="post-metadata">

**Author:** ![heldopslippers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b9bd4f/32.png) [@heldopslippers](https://www.ruby-forum.com/u/heldopslippers)\
**Post date:** [November 1, 2007, 11:49pm UTC](https://www.ruby-forum.com/t/action-in-a-action-from-an-other-controller/118961/7 "2007-11-01T23:49:23Z")

</div>

You can either put them in a module as has already been mentioned, and  
then include them in your controllers, or you can put them in helpers/  
application\_helper, or you can put them in ApplicationController as  
all your other controllers subclass this, meaning they would  
automatically inherit them.

On Nov 1, 10:27 pm, Heldop S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![heldopslippers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b9bd4f/32.png) [@heldopslippers](https://www.ruby-forum.com/u/heldopslippers)\
**Post date:** [November 2, 2007, 12:43am UTC](https://www.ruby-forum.com/t/action-in-a-action-from-an-other-controller/118961/8 "2007-11-02T00:43:26Z")

</div>

Matt Su wrote:

> You can either put them in a module as has already been mentioned, and  
> then include them in your controllers, or you can put them in helpers/  
> application\_helper, or you can put them in ApplicationController as  
> all your other controllers subclass this, meaning they would  
> automatically inherit them.
> 
> On Nov 1, 10:27 pm, Heldop S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

ok… I did that (put almost all of it in the applicationController) … A  
shame it isn’t possible to put it in other controller… but wel…

thanxs for the reply’s all …
