1

Topic: what is the "rails" way of rendering multiple model lists in one page?

I'm hoping someone can help me with what must be a very common requirement.  I have a page that shows summary lists from multiple models, e.g. articles and users.  Current design has each model paired w/ its own controller.  My implementation for implementing two lists in one page was to use render_component(), calling the appropriate "list" action for each and rendering the resulting page.  But I have read that this is generally frowned upon for being slow and inefficient.  I've read threads recommending to use render_partial, perhaps with a "before_filter", but some component has to prepare the data for the partial templates, and it seems artificial to have this preparation be anywhere other than in the appropriate controller.

What is the correct architecture for implementing this requirement?

thx

F

Re: what is the "rails" way of rendering multiple model lists in one page?

I dont know about the correct procedure, but if I'm using a partial that needs somthing before it renders and the controller is'nt suitable I'll use one of the helper files.

--

Re: what is the "rails" way of rendering multiple model lists in one page?

ff,

Great question, I'm lookin for the same answer, basically to setup an admin section.  Could you even take a step back and maybe explain some resources you used to arrive at your current solution?

Re: what is the "rails" way of rendering multiple model lists in one page?

ff wrote:

I've read threads recommending to use render_partial, perhaps with a "before_filter", but some component has to prepare the data for the partial templates, and it seems artificial to have this preparation be anywhere other than in the appropriate controller.

What is the correct architecture for implementing this requirement?

I'm assuming the "list" actions are just performing a "find" on the model? In this case I don't think it is a problem to copy this find into the action which displays multiple models. This is because you may want to list the items on this page in a different way than on the full list page. You might not want to display as many, or perhaps you want them in a different order. It is a completely different find request. If there's any duplication beyond a simple find I recommend moving it into the model.

Railscasts - Free Ruby on Rails Screencasts