Observer Observer - 1 year ago 331
Ruby Question

Rails: How to avoid AbstractController::DoubleRenderError when using live update / Faye?

I'm using Private Pub which is a gem built on top of Faye for live updating through my controller. I'm having trouble to be able to make a fallback for the Live Update Render, in case Faye server failed to serve.

Is there anyway to go around this situation and render second time if my first render method failed?

Here is my


def create
#assigning objects and such happening here

rescue => exception

end # end rescue

Normally when the error occurs, it should go to the 2nd block and ignore the first one. While here it doesn't because it says that:

occurred in

Render and/or redirect were called multiple times in this action.
Please note that you may only call render OR redirect, and at most
once per action. Also note that neither redirect nor render terminate
execution of the action, so if you want to exit an action after
redirecting, you need to do something like "redirect_to(...) and
return". app/controllers/my_controller.rb130:in `block
(2 levels) in normalAjaxRender'

Answer Source

In order to avoid the redundancy of the Rendering this is what I did:

Set normalAjaxRender() method as default and in the JS file I added rescue and liveupdate