【问题标题】:Strange DoubleRenderError in Rails 3Rails 3中奇怪的DoubleRenderError
【发布时间】:2010-09-02 08:14:46
【问题描述】:

我正在尝试标准的 redirect_to some_path and return 语法,但出于某种原因 Rails 3 不喜欢这个。

class MyController < ApplicationController
  def some_action
    redirect_to "http://www.google.com"
    return
  end
end

给我标准的错误信息:

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".

它在错误中引用了我的redirect_to "http://www.google.com" 的确切行。无法弄清楚这怎么可能!

在我能找到的过滤器之前我已经注释掉了,没有区别。

这是 Rails 3.0.0

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3


    【解决方案1】:

    哦,伙计——终于想通了。

    我在上面放置some_action 的地方实际上已将方法命名为status。显然这是一个保留字或 rails 中的某些东西,因为它是从其他地方调用它 - 因此是 DoubleRender 错误。

    哇 - 我解决问题的时间比它应该解决的要长。

    【讨论】:

    • 这里有同样的问题。该死的和那些保留字。如果只有错误会说明问题出在哪里... =)
    • 哇,我希望这被记录下来,这让我很受打击......只是突然出现在生产中,尽管我有一个名为“状态”的动作几个月来!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多