I am using Ruby on Rails and am trying to load a page which consists of many sub-pages. Each sub-page is pretty different and the data for each sub-page is generated by a separate action in the controller. Upon loading the main page, I want to also load the content for the sub-pages by calling the corresponding actions.
So my question is whether it is possible to fire off multiple requests to different actions upon a single page request. If so, what is the best way to achieve this so that the resulting views from each action are displayed in the right parts of the page? If it’s not possible, how else can I load content processed from different actions in a single request?
Ideally, the actions for sub-pages can be called from different places (e.g. the sub-page can be a component of a different pages and could also be its own page). I want to abstract out the place from where an action is being called from the controller so I can simply render the appropriate partial for the data generated by the controller. But the key is that this partial is not going to be determined in the controller, but rather in the view. Has something like this been done? Is there an even better alternative?
Thanks!
What you want to do should not by solved by calling different actions.
In the controller, you know which models you want to display in the view, so you set up the attributes accordingly, e.g.
In your view, you then use partials to render the different parts of your site
I suggest you have a look at Opensourcerails, which itself is open source and makes use of this technique. A good example is the user’s show action.