0

我正在使用 Private Pub,它是在 Faye 之上构建的一个 gem,用于通过我的控制器进行实时更新。我无法为实时更新渲染进行回退,以防 Faye 服务器无法提供服务。

如果我的第一个渲染方法失败,是否有办法绕过这种情况并第二次渲染?

这是我的create行动:

  def create
    #assigning objects and such happening here

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

        normalAjaxRender(@comment)
    end # end rescue
  end

通常当错误发生时,它应该转到第二个块并忽略第一个。虽然在这里它不是因为它说:

发生AbstractController::DoubleRenderErroruser_comments#create

在此操作中多次调用渲染和/或重定向。请注意,您只能调用渲染或重定向,并且每个操作最多调用一次。另请注意,重定向和渲染都不会终止操作的执行,因此如果您想在重定向后退出操作,则需要执行“redirect_to(...) and return”之类的操作。app/controllers/my_controller.rb130:in `block (2 levels) in normalAjaxRender'

4

1 回答 1

0

为了避免渲染的冗余,这就是我所做的:

normalAjaxRender()方法设置为默认值并在JS我添加的文件rescueliveupdate

于 2014-06-02T22:00:46.843 回答