0

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 create action:

  def create
    #assigning objects and such happening here

    begin
        LiveAjaxRender(@comment)
    rescue => exception
        ExceptionNotifier.notify_exception(exception)

        normalAjaxRender(@comment)
    end # end rescue
  end

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:

An AbstractController::DoubleRenderError occurred in user_comments#create:

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'

dds
  • 2,335
  • 1
  • 31
  • 45
0bserver07
  • 3,390
  • 1
  • 28
  • 56
  • Inside `normalAjaxRender` you tried to do double rendering.. It is clear from the error message. check the logic inside it. – Arup Rakshit Jun 02 '14 at 16:49
  • This is all I have in the method `def normalAjaxRender(post)` `@post = comment` `if @post.save` `respond_to do |format|` `format.html { }` `format.js { render :posts }` `end` `else` `render :new` `end` ``end`` – 0bserver07 Jun 02 '14 at 17:35
  • Ok.. Put it inside the post... *There you go* Inside *respond_to*, you are doing *render* also.. This is not allowed, thus you got error. – Arup Rakshit Jun 02 '14 at 17:38
  • @ArupRakshit, Thanks for you explanation, I'm trying to make the action do 1 render not two. If First render fails then I want to make the 2nd render method work. Maybe my question is not clear enough, but I want to figure out on how to to pick one of them. – 0bserver07 Jun 02 '14 at 17:43

1 Answers1

0

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

0bserver07
  • 3,390
  • 1
  • 28
  • 56