Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
297a579d
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,发现更多精彩内容 >>
提交
297a579d
编写于
5月 30, 2017
作者:
V
Vinicius Stock
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Create MissingExactTemplate exception with separate template
上级
b6ee4e4b
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
37 addition
and
20 deletion
+37
-20
actionpack/lib/action_controller/metal/exceptions.rb
actionpack/lib/action_controller/metal/exceptions.rb
+3
-0
actionpack/lib/action_controller/metal/implicit_render.rb
actionpack/lib/action_controller/metal/implicit_render.rb
+2
-12
actionpack/lib/action_dispatch/middleware/exception_wrapper.rb
...npack/lib/action_dispatch/middleware/exception_wrapper.rb
+7
-5
actionpack/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.html.erb
...dleware/templates/rescues/missing_exact_template.html.erb
+19
-0
actionpack/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.text.erb
...dleware/templates/rescues/missing_exact_template.text.erb
+3
-0
actionpack/test/controller/mime/respond_to_test.rb
actionpack/test/controller/mime/respond_to_test.rb
+2
-2
actionpack/test/controller/render_test.rb
actionpack/test/controller/render_test.rb
+1
-1
未找到文件。
actionpack/lib/action_controller/metal/exceptions.rb
浏览文件 @
297a579d
...
...
@@ -50,4 +50,7 @@ class UnknownHttpMethod < ActionControllerError #:nodoc:
class
UnknownFormat
<
ActionControllerError
#:nodoc:
end
class
MissingExactTemplate
<
UnknownFormat
#:nodoc:
end
end
actionpack/lib/action_controller/metal/implicit_render.rb
浏览文件 @
297a579d
...
...
@@ -41,18 +41,8 @@ def default_render(*args)
raise
ActionController
::
UnknownFormat
,
message
elsif
interactive_browser_request?
message
=
"
#{
self
.
class
.
name
}
\#
#{
action_name
}
is missing a template "
\
"for this request format and variant.
\n\n
"
\
"request.formats:
#{
request
.
formats
.
map
(
&
:to_s
).
inspect
}
\n
"
\
"request.variant:
#{
request
.
variant
.
inspect
}
\n\n
"
\
"NOTE! For XHR/Ajax or API requests, this action would normally "
\
"respond with 204 No Content: an empty white screen. Since you're "
\
"loading it in a web browser, we assume that you expected to "
\
"actually render a template, not nothing, so we're showing an "
\
"error to be extra-clear. If you expect 204 No Content, carry on. "
\
"That's what you'll get from an XHR or API request. Give it a shot."
raise
ActionController
::
UnknownFormat
,
message
message
=
"
#{
self
.
class
.
name
}
\#
#{
action_name
}
is missing a template for request formats:
#{
request
.
formats
.
map
(
&
:to_s
).
join
(
','
)
}
"
raise
ActionController
::
MissingExactTemplate
,
message
else
logger
.
info
"No template found for
#{
self
.
class
.
name
}
\#
#{
action_name
}
, rendering head :no_content"
if
logger
super
...
...
actionpack/lib/action_dispatch/middleware/exception_wrapper.rb
浏览文件 @
297a579d
...
...
@@ -12,6 +12,7 @@ class ExceptionWrapper
"ActionController::UnknownHttpMethod"
=>
:method_not_allowed
,
"ActionController::NotImplemented"
=>
:not_implemented
,
"ActionController::UnknownFormat"
=>
:not_acceptable
,
"ActionController::MissingExactTemplate"
=>
:not_acceptable
,
"ActionController::InvalidAuthenticityToken"
=>
:unprocessable_entity
,
"ActionController::InvalidCrossOriginRequest"
=>
:unprocessable_entity
,
"ActionDispatch::Http::Parameters::ParseError"
=>
:bad_request
,
...
...
@@ -22,11 +23,12 @@ class ExceptionWrapper
)
cattr_accessor
:rescue_templates
,
default:
Hash
.
new
(
"diagnostics"
).
merge!
(
"ActionView::MissingTemplate"
=>
"missing_template"
,
"ActionController::RoutingError"
=>
"routing_error"
,
"AbstractController::ActionNotFound"
=>
"unknown_action"
,
"ActiveRecord::StatementInvalid"
=>
"invalid_statement"
,
"ActionView::Template::Error"
=>
"template_error"
"ActionView::MissingTemplate"
=>
"missing_template"
,
"ActionController::RoutingError"
=>
"routing_error"
,
"AbstractController::ActionNotFound"
=>
"unknown_action"
,
"ActiveRecord::StatementInvalid"
=>
"invalid_statement"
,
"ActionView::Template::Error"
=>
"template_error"
,
"ActionController::MissingExactTemplate"
=>
"missing_exact_template"
,
)
attr_reader
:backtrace_cleaner
,
:exception
,
:line_number
,
:file
...
...
actionpack/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.html.erb
0 → 100644
浏览文件 @
297a579d
<header>
<h1>
No template for interactive request
</h1>
</header>
<div
id=
"container"
>
<h3>
<%=
h
@exception
.
message
%>
</h3>
<p
class=
"summary"
>
<strong>
NOTE!
</strong><br>
Unless told otherwise, Rails expects an action to render a template with the same name,
<br>
contained in a folder named after its controller.
If this controller is an API responding with 204 (No Content),
<br>
which does not require a template,
then this error will occur when trying to access it via browser,
<br>
since we expect an HTML template
to be rendered for such requests. If that's the case, carry on.
</p>
</div>
actionpack/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.text.erb
0 → 100644
浏览文件 @
297a579d
Missing exact template
<%=
@exception
.
message
%>
actionpack/test/controller/mime/respond_to_test.rb
浏览文件 @
297a579d
...
...
@@ -658,13 +658,13 @@ def test_variant_with_implicit_template_rendering
end
def
test_variant_without_implicit_rendering_from_browser
assert_raises
(
ActionController
::
UnknownFormat
)
do
assert_raises
(
ActionController
::
MissingExactTemplate
)
do
get
:variant_without_implicit_template_rendering
,
params:
{
v: :does_not_matter
}
end
end
def
test_variant_variant_not_set_and_without_implicit_rendering_from_browser
assert_raises
(
ActionController
::
UnknownFormat
)
do
assert_raises
(
ActionController
::
MissingExactTemplate
)
do
get
:variant_without_implicit_template_rendering
end
end
...
...
actionpack/test/controller/render_test.rb
浏览文件 @
297a579d
...
...
@@ -650,7 +650,7 @@ class ImplicitRenderTest < ActionController::TestCase
tests
ImplicitRenderTestController
def
test_implicit_no_content_response_as_browser
assert_raises
(
ActionController
::
UnknownFormat
)
do
assert_raises
(
ActionController
::
MissingExactTemplate
)
do
get
:empty_action
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录