# Calling an action in another controller

**URL:** <https://www.ruby-forum.com/t/calling-an-action-in-another-controller/87171>\
**Category:** Rails\
**Created:** [March 25, 2006, 7:19pm UTC](https://www.ruby-forum.com/t/calling-an-action-in-another-controller/87171 "2006-03-25T19:19:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ac91a4/32.png) [@bill](https://www.ruby-forum.com/u/bill)\
**Post date:** [March 25, 2006, 7:19pm UTC](https://www.ruby-forum.com/t/calling-an-action-in-another-controller/87171/1 "2006-03-25T19:19:54Z")

</div>

I have two controllers, one for lists and one for list items. When I’m  
viewing a list I’d like to have a link to create list items within that  
list. How do I go about calling an action in the listitems controller  
to create a new item within that specific list?

Thanks

---

<div class="post-metadata">

**Author:** ![bill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ac91a4/32.png) [@bill](https://www.ruby-forum.com/u/bill)\
**Post date:** [March 26, 2006, 12:28am UTC](https://www.ruby-forum.com/t/calling-an-action-in-another-controller/87171/2 "2006-03-26T00:28:52Z")

</div>

Hi Bill ~

I think your design might be flawed here. You probably want one list  
controller with several actions. Maybe a list action to show all the  
items and a list\_add action to add an item. You can link to another  
controller, but it is not very DRY.

If you really want to link to the action in the other controller, you  
can do:

\<%= link\_to(“New list Item”, :controller =\> “listitem”, :action =\>  
“ACTION YOU WANT TO CALL HERE”) %\>

If they were in the same controller, you can just do:

\<%= link\_to(“New list Item”, :action =\> “ACTION YOU WANT TO CALL HERE”)  
%\>

Hope this helps,

~ Ben

On 3/25/06, Bill [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Ben R.  
[http://www.benr75.com](http://www.benr75.com)

---

<div class="post-metadata">

**Author:** ![bill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ac91a4/32.png) [@bill](https://www.ruby-forum.com/u/bill)\
**Post date:** [March 26, 2006, 12:59am UTC](https://www.ruby-forum.com/t/calling-an-action-in-another-controller/87171/3 "2006-03-26T00:59:22Z")

</div>

Ben R. wrote:

> Hi Bill ~
> 
> I think your design might be flawed here. You probably want one list  
> controller with several actions. Maybe a list action to show all the  
> items and a list\_add action to add an item. You can link to another  
> controller, but it is not very DRY.
> 
> If you really want to link to the action in the other controller, you  
> can do:
> 
> \<%= link\_to(“New list Item”, :controller =\> “listitem”, :action =\>  
> “ACTION YOU WANT TO CALL HERE”) %\>
> 
> If they were in the same controller, you can just do:
> 
> \<%= link\_to(“New list Item”, :action =\> “ACTION YOU WANT TO CALL HERE”)  
> %\>
> 
> Hope this helps,
> 
> ~ Ben
> 
> On 3/25/06, Bill [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Rails mailing list  
> > removed\_email\_address@domain.invalid  
> > [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)
> 
> –  
> Ben R.  
> [http://www.benr75.com](http://www.benr75.com)

Thanks Ben, it helps a lot.

Bill
