我想知道为什么在 before_action
中有 redirect_to
或 render
时没有双重渲染。考虑这个例子:
class SomeController < ApplicationController
before_action :callback
def new
callback2
render 'new'
end
def callback
render 'new'
end
def callback2
render 'new'
end
end
我看到 before_action
如果不能重定向就没用了,但它是如何制作的?如果我评论 before_action
它会抛出异常。
before_action
是如何实现的而不导致双重渲染?
最佳答案
参见 Rails Guide on controllers :
If a "before" filter renders or redirects, the action will not run. If there are additional filters scheduled to run after that filter, they are also cancelled.
关于ruby-on-rails - 为什么使用 before_action 没有双重渲染?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30168937/