ruby-on-rails – 如何在搜索错误时跟踪rails应用程序中的redirect_to

栏目: Ruby · 发布时间: 7年前

内容简介:在调试问题时,当您拥有大量gem和before_filters时,很难在rails应用程序中跟踪redirect_to.那么有没有一种方法可以更快地追踪它们?可用的任何方法或铁路助手?翻译自:https://stackoverflow.com/questions/15274038/how-to-trace-redirect-to-in-a-rails-app-while-hunting-bugs

在调试问题时,当您拥有大量gem和before_filters时,很难在rails应用程序中跟踪redirect_to.那么有没有一种方法可以更快地追踪它们?可用的任何方法或铁路助手?

在应用程序控制器中添加以下方法

def redirect_to(options = {}, response_status = {})
  ::Rails.logger.error("Redirected by #{caller(1).first rescue "unknown"}")
  super(options, response_status)
end

然后你将能够看到在日志文件中调用’redirect_to’调用的文件,方法名称(它将被记录)

例如:

Started GET "http://server.com/really_important_page" for 127.0.0.1
Processing by HomeController#really_important_page as HTML
Redirected by app/controllers/application_controller.rb:53:in `ensure_random_bugs'
Redirected to https://server.com/not_the_page_you_wanted
Completed 302 Found in 1ms

这节省了我的一天所以想在这里分享,希望你发现它有用:)

翻译自:https://stackoverflow.com/questions/15274038/how-to-trace-redirect-to-in-a-rails-app-while-hunting-bugs


以上所述就是小编给大家介绍的《ruby-on-rails – 如何在搜索错误时跟踪rails应用程序中的redirect_to》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

The Little Schemer

The Little Schemer

[美] Daniel P. Friedman、[美] Matthias Felleisen / 卢俊祥 / 电子工业出版社 / 2017-7 / 65.00

《The Little Schemer:递归与函数式的奥妙》是一本久负盛名的经典之作,两位作者Daniel P. Friedman、Matthias Felleisen在程序语言界名声显赫。《The Little Schemer:递归与函数式的奥妙》介绍了Scheme的基本结构及其应用、Scheme的五法十诫、Continuation-Passing-Style、Partial Function、......一起来看看 《The Little Schemer》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具