我总是收到以下错误:
AbstractController::DoubleRenderError (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".):
当 id 第一次为 nil 时,会发生错误,但第二次则不会......
def calc_next
id = next()
if id.nil?
id = next_next()
if id.nil?
render :layout => false, :format => :js
else
redirect_to :action => "view", :id => id, :format => :js
end
else
redirect_to :action => "view", :id => id, :format => :js
end
end
我在这个重定向中没有看到问题,因为外部重定向没有问题。即使使用调试器,也不会同时进行两个重定向...
感谢任何帮助... 马库斯
最佳答案
这看起来像是某种辅助函数,而不是 Controller 操作。在这种情况下,您可能会调用 calc_next
一次操作两次,或 render
/redirect_to
从其他地方进行相同的操作。请记住render
和redirect_to
不要立即导致 Controller 返回。
检查您的控制路径是否可以同时调用 calc_next
并调用render
或redirect_to
从其他地方(或从第二次调用 calc_next
)。
如果您发布您正在经历的 Controller 操作,我们也许能够提供更好的帮助。
关于ruby-on-rails-3 - Rails 3 中的 AbstractController::DoubleRenderError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6941971/