Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
083f657c
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
083f657c
编写于
12月 01, 2014
作者:
K
Kir Shatrov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor debug view
Avoid logic in ERB and use helpers
上级
cd77755a
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
54 addition
and
23 deletion
+54
-23
actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
...onpack/lib/action_dispatch/middleware/debug_exceptions.rb
+29
-1
actionpack/lib/action_dispatch/middleware/exception_wrapper.rb
...npack/lib/action_dispatch/middleware/exception_wrapper.rb
+0
-1
actionpack/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb
...ddleware/templates/rescues/_request_and_response.html.erb
+2
-21
actionpack/test/dispatch/debug_exceptions_test.rb
actionpack/test/dispatch/debug_exceptions_test.rb
+23
-0
未找到文件。
actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
浏览文件 @
083f657c
...
...
@@ -2,12 +2,40 @@
require
'action_dispatch/middleware/exception_wrapper'
require
'action_dispatch/routing/inspector'
require
'pp'
module
ActionDispatch
# This middleware is responsible for logging exceptions and
# showing a debugging page in case the request is local.
class
DebugExceptions
RESCUES_TEMPLATE_PATH
=
File
.
expand_path
(
'../templates'
,
__FILE__
)
class
DebugView
<
ActionView
::
Base
def
debug_params
(
params
)
clean_params
=
params
.
clone
clean_params
.
delete
(
"action"
)
clean_params
.
delete
(
"controller"
)
if
clean_params
.
empty?
'None'
else
PP
.
pp
(
clean_params
,
""
,
200
)
end
end
def
debug_headers
(
headers
)
if
headers
.
present?
headers
.
inspect
.
gsub
(
','
,
",
\n
"
)
else
'None'
end
end
def
debug_hash
(
object
)
object
.
to_hash
.
sort_by
{
|
k
,
_
|
k
.
to_s
}.
map
{
|
k
,
v
|
"
#{
k
}
:
#{
v
.
inspect
rescue
$!
.
message
}
"
}.
join
(
"
\n
"
)
end
end
def
initialize
(
app
,
routes_app
=
nil
)
@app
=
app
@routes_app
=
routes_app
...
...
@@ -46,7 +74,7 @@ def render_exception(env, exception)
source_to_show_id
=
source_to_show
[
:id
]
end
template
=
ActionView
::
Base
.
new
([
RESCUES_TEMPLATE_PATH
],
template
=
DebugView
.
new
([
RESCUES_TEMPLATE_PATH
],
request:
request
,
exception:
wrapper
.
exception
,
traces:
traces
,
...
...
actionpack/lib/action_dispatch/middleware/exception_wrapper.rb
浏览文件 @
083f657c
require
'action_controller/metal/exceptions'
require
'active_support/core_ext/module/attribute_accessors'
require
'pp'
module
ActionDispatch
class
ExceptionWrapper
...
...
actionpack/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb
浏览文件 @
083f657c
...
...
@@ -5,27 +5,8 @@
<pre
id=
"blame_trace"
<%=
'style="display:none"'
if
hide
%>
><code>
<%=
@exception
.
describe_blame
%>
</code></pre>
<%
end
%>
<%
clean_params
=
@request
.
filtered_parameters
.
clone
clean_params
.
delete
(
"action"
)
clean_params
.
delete
(
"controller"
)
request_dump
=
if
clean_params
.
empty?
'None'
else
pretty_params
=
""
PP
.
pp
(
clean_params
,
pretty_params
,
200
)
pretty_params
end
def
debug_hash
(
object
)
object
.
to_hash
.
sort_by
{
|
k
,
_
|
k
.
to_s
}.
map
{
|
k
,
v
|
"
#{
k
}
:
#{
v
.
inspect
rescue
$!
.
message
}
"
}.
join
(
"
\n
"
)
end
unless
self
.
class
.
method_defined?
(
:debug_hash
)
%>
<h2
style=
"margin-top: 30px"
>
Request
</h2>
<p><b>
Parameters
</b>
:
</p>
<pre>
<%=
request_dump
%>
</pre>
<p><b>
Parameters
</b>
:
</p>
<pre>
<%=
debug_params
(
@request
.
filtered_parameters
)
%>
</pre>
<div
class=
"details"
>
<div
class=
"summary"
><a
href=
"#"
onclick=
"return toggleSessionDump()"
>
Toggle session dump
</a></div>
...
...
@@ -38,4 +19,4 @@
</div>
<h2
style=
"margin-top: 30px"
>
Response
</h2>
<p><b>
Headers
</b>
:
</p>
<pre>
<%=
de
fined?
(
@response
)
?
@response
.
headers
.
inspect
.
gsub
(
','
,
",
\n
"
)
:
'None'
%>
</pre>
<p><b>
Headers
</b>
:
</p>
<pre>
<%=
de
bug_headers
(
defined?
(
@response
)
?
@response
.
headers
:
{})
%>
</pre>
actionpack/test/dispatch/debug_exceptions_test.rb
浏览文件 @
083f657c
...
...
@@ -241,6 +241,29 @@ def setup
assert_match
(
/RuntimeError\n\s+in FeaturedTileController/
,
body
)
end
test
"show formatted params"
do
@app
=
DevelopmentApp
params
=
{
'id'
=>
'unknown'
,
'someparam'
=>
{
'foo'
=>
'bar'
,
'abc'
=>
'goo'
}
}
get
(
"/runtime_error"
,
{},
{
'action_dispatch.show_exceptions'
=>
true
,
'action_dispatch.request.parameters'
=>
{
'action'
=>
'show'
,
'controller'
=>
'featured_tile'
}.
merge
(
params
)
})
assert_response
500
assert_includes
(
body
,
CGI
.
escapeHTML
(
PP
.
pp
(
params
,
""
,
200
)))
end
test
"sets the HTTP charset parameter"
do
@app
=
DevelopmentApp
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录