Calling an action in another controller


#1

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


#2

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


#3

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