Rails,处理多个重定向
我有一个程序,其中一个 gem,facebooker,调用重定向,并在同一操作中我最终通过 redirect_back_or_default
调用重定向。我的问题是:
- 有没有办法捕获多重重定向错误?开始/救援块似乎没有做到这一点。
- 或者,有没有一种方法可以检查重定向是否已被调用,这样我就不会调用下一个?
此时,我不想修改 facebooker gem,那么您认为处理此问题的最佳方法是什么?
谢谢大家, 贾斯汀
I have a program where a gem, facebooker, calls a redirect and in the same action I end up callling a redirect through redirect_back_or_default
. My question is:
- Is there a way to catch the multiple redirect error? A begin/rescue block doesn't seem to do it.
- Or, is there a way to check to see if a redirect has already been called so I don't call the next one?
At this point, I don't want to modify the facebooker gem, so what do you feel is the best way to handle this?
Thanks all,
Justin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 ActionController#redirect_to 的来源 帮助:
你可以像这样拯救异常(并且只保留日志行):
或者你可以测试(在我看来这没有好的做法)response_body,类似于ActionController 的作用是:
A look at the source of ActionController#redirect_to helps out:
You could rescue the Exception like this (and just leave the log line out):
or you can test (in my opinion this is no good practice) for response_body similar to what the ActionController does: