开发者

Strange DoubleRenderError in Rails 3

开发者 https://www.devze.com 2023-01-13 22:34 出处:网络
I\'m trying the standard redirect_to some_path and return sy开发者_如何学运维ntax but for some reason Rails 3 isn\'t liking this.

I'm trying the standard redirect_to some_path and return sy开发者_如何学运维ntax but for some reason Rails 3 isn't liking this.

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

Gives me the standard error message:

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

It references the exact line of my redirect_to "http://www.google.com" in the error. Can't figure out how this is possible!

I've commented out all before filters I can find, no difference.

This is Rails 3.0.0


Oh man - finally figured it out.

Where I put some_action above I had actually named the method status. Apparently this is a reserved word or something in rails because it was calling it from somewhere else - hence the DoubleRender error.

Wow - that took me way longer to solve than it should have.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号