为什么redirect_to在around_filter或after_filter不起作用? [英] Why redirect_to in around_filter or after_filter won't work?

查看:122
本文介绍了为什么redirect_to在around_filter或after_filter不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使redirect_to在这些过滤器中起作用?



我试图改变

  def start 
...
redirect_to索引
结束

结束
...
redirect_to索引
结束

  around_filter:大约

def
...
收益
redirect_to索引
结束

开始
..
end

def stop
...
end


<在动作完成后,它会自动呈现模板,因此在请求完成后您不能呈现/重定向。你可以通过把 redirect_to 放在你需要的操作的最后来解决这个问题。这不是 around_filters 被设计来做的。


How to make redirect_to works in those filters?

I'm trying to change

def start 
  ....
  redirect_to index
end

def end
  ...
  redirect_to index
end  

to

around_filter :around

def around
  ...
  yield
  redirect_to index
end 

def start
  ..
end

def stop
  ...
end

解决方案

After the action is complete it renders the template automatically, thus you cannot render / redirect after the request is complete. You could solve this by putting the redirect_to at the end of the actions that you need it for. This is not what around_filters were designed to do.

这篇关于为什么redirect_to在around_filter或after_filter不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆