Forum: Ruby on Rails Calling an action in another controller

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Bill (Guest)
on 2006-03-25 20:19
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
Ben R. (Guest)
on 2006-03-26 01:28
(Received via mailing list)
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> wrote:
> Rails mailing list
> removed_email_address@domain.invalid
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
Ben R.
http://www.benr75.com
Bill (Guest)
on 2006-03-26 01:59
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> wrote:
>> Rails mailing list
>> removed_email_address@domain.invalid
>> http://lists.rubyonrails.org/mailman/listinfo/rails
>>
>
>
> --
> Ben R.
> http://www.benr75.com


Thanks Ben, it helps a lot.

Bill
This topic is locked and can not be replied to.