弄清楚哪个元素触发了请求

时间:2012-03-06 16:10:47

标签: ruby-on-rails ruby

我目前正在开发一个由5人开发的大型项目。 问题是每次加载特定页面时,我都会得到一个迷失的POST请求以及页面的GET请求。该页面不包含任何形式,尽管使用了大量的jquery。

Started POST "/my_profile" for 127.0.0.1 at 2012-03-06 21:34:23 +0530
ActionController::RoutingError (No route matches "/my_profile"): 

有没有办法找出哪个元素或脚本触发了这个POST请求,而不是通过整个代码分成20个部分和2个javascripts?

2 个答案:

答案 0 :(得分:2)

如果您使用的是Firefox,请查看Firebug插件。通过网络面板,您可以轻松跟踪给定页面加载的任何POST / GET请求。

答案 1 :(得分:1)

您可以尝试[binding_of_caller][1]caller或可能[set_trace_func][2]

Dzone Snippets提供了一种使用caller的强大方法:

def caller_method_name
    parse_caller(caller(2).first).last
end

def parse_caller(at)
    if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
        file = Regexp.last_match[1]
        line = Regexp.last_match[2].to_i
        method = Regexp.last_match[3]
        [file, line, method]
    end
end

或者您可以执行caller.inspect并查看原始输出。

Binding_of_caller涉及更多,可能对你想要的东西有点过分,但如果caller不是你需要的话,请查看它。与set_trace_func相同。

相关问题