Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3: How to render an action from another controller's view

I'm trying to call an action from a different controller's view:

Controller Countries has an action called selectbox which generates a html selectbox from all countries as a partial.
Controller Customers has an action called new which generates a html form for all the customers attributes. I want to insert the selectbox from Countries#selectbox in this form.

What would be the right way to achieve this?

like image 312
silent Avatar asked Feb 03 '26 21:02

silent


1 Answers

You're doing it wrong. If there's a piece of code that is to be reused (such as html selectbox generation), you should put it in a helper and/or use a partial to render the html selectbox part.

Bear in mind this is only good advice if the code is somewhat complex (say, more than one or two lines). Here's a post I found while googling that may help you: helper or partial

like image 103
Miguel Ping Avatar answered Feb 06 '26 13:02

Miguel Ping