ruby-on-rails-3 - Rails 3 中的 AbstractController::DoubleRenderError

标签 ruby-on-rails-3 redirect

我总是收到以下错误:

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从其他地方进行相同的操作。请记住renderredirect_to 不要立即导致 Controller 返回。

检查您的控制路径是否可以同时调用 calc_next并调用renderredirect_to从其他地方(或从第二次调用 calc_next )。

如果您发布您正在经历的 Controller 操作,我们也许能够提供更好的帮助。

关于ruby-on-rails-3 - Rails 3 中的 AbstractController::DoubleRenderError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6941971/

相关文章:

ruby-on-rails - #<Rails::Application::Configuration> 的未定义方法 `assets'

ruby-on-rails - 将 ActionDispatch::Http::UploadedFile 上传到 Amazon S3

ruby-on-rails - 带有设计的嵌套形式

.htaccess - 临时重定向到维护页面

mysql - Rails 3 ActiveRecord 查询接口(interface),按每个父项的最近创建的子项排序父项

mysql - 获取随机记录

Bash,标准输出重定向命令,如 scp

JavaScript 重定向 URL

java - 将 System.out 重定向到页面

linux - 重定向器中的环境变量,完善我的日志脚本