I have a view for a controller called \"show\". Inside that view, i want to render the contents of another controller\'s view - and obviously, the logic for the form on that vi
If you really want to render entirely another action (i.e. simulating a request to go through the entire Ruby on Rails stack), you can use Webrat (check Webrat screencast here).
In traditional MVC web applications, you should rarely have a need to do this. But in my experience developing SOFEA-style and micro-architecture webapps, this is getting more and more common.
I'm not sure I understand your problem statement fully (why this must be done from the view), but I'd say you just call redirect_to
from controller A to controller B.
The terminology in your question is a little confused. If are in a controller and you want to execute the code in another action method in another controller and render its template, you should redirect_to that action. Let's say the other controller is called ContractsController
redirect_to :controller => "contracts", :action => "show_home_page"
If you just want to use the view template from another method as the response from your action, you just need to prefix the name of the controller in the render parameter. This will not call the action, it will just use its template.
For example, if the template lives in the folder for the contracts controller.
render :action => "/contracts/show_home_page", :layout=> false
I think in this case you are actually talking about a partial, which would look like
render :partial => "/contracts/show_home_page"
However, what I see you grasping at here is that you actually want to call multiple action methods to render a single page. This is not how it works. You are going to have to set up the objects that the templates will reference in a single action. This is one reason most Rails developers put a lot of code in the models, so the setup isn't repeated all over the controllers.
But there is another way... where the magic of JavaScript comes in.
In your page, create a function like this:
<script type="text/javascript" language="javascript">
function load_categories() {
<%= remote_function(:url => {:controller => "categories", :action => "list"},
:update => "categories")%>
};
</script>
If you call that in the onload even of your page, it will replace the div with id "categories" with the response from the action referenced.