Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rendering multiple partials in a controller

I want to render multiple partials in a controller, these will not be part of the response, but pushed to clients via Juggernaut instead.

I'm using render_to_string.

When the second one is called, I get a DoubleRenderError.

How do I render a partial the way that performed? will not be affected?

like image 906
Leventix Avatar asked Mar 04 '10 00:03

Leventix


People also ask

How do I return multiple partial views from a controller?

You can only return one value from a function so you can't return multiple partials from one action method. If you are trying to return two models to one view, create a view model that contains both of the models that you want to send, and make your view's model the new ViewModel.

Which method is used to render partials?

Rendering a Partial View You can render the partial view in the parent view using the HTML helper methods: @html. Partial() , @html. RenderPartial() , and @html. RenderAction() .

Can partial view have controller?

It does not require to have a controller action method to call it. Partial view data is dependent of parent model. Caching is not possible as it is tightly bound with parent view (controller action method) and parent's model.

What is partial render?

The primary difference between the two methods is that Partial generates the HTML from the View and returns it to the View to be incorporated into the page. RenderPartial, on the other hand, doesn't return anything and, instead, adds its HTML directly to the Response object's output.


2 Answers

It turns out render_to_string clears off "render results", so you can call it multiple times. The problem was that I called render_to_string in an after_filter hook, after a render was already called.

like image 81
Leventix Avatar answered Oct 21 '22 05:10

Leventix


wait so how can you do this in a after_filter hook? cause im running into the same issue, and have to do an after_filter hook.

btw, im in a similar situation using push tech, but with HTML 5 websockets, and eventmachine

like image 21
taelor Avatar answered Oct 21 '22 04:10

taelor