Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
0de4a23d
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,体验更适合开发者的 AI 搜索 >>
提交
0de4a23d
编写于
3月 17, 2015
作者:
S
Stephen Bussey
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
head no_content when there is no template or action performed
上级
9040699a
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
31 addition
and
8 deletion
+31
-8
actionpack/CHANGELOG.md
actionpack/CHANGELOG.md
+8
-0
actionpack/lib/action_controller/metal/implicit_render.rb
actionpack/lib/action_controller/metal/implicit_render.rb
+6
-1
actionpack/test/controller/mime/respond_to_test.rb
actionpack/test/controller/mime/respond_to_test.rb
+16
-6
actionview/lib/action_view/lookup_context.rb
actionview/lib/action_view/lookup_context.rb
+1
-1
未找到文件。
actionpack/CHANGELOG.md
浏览文件 @
0de4a23d
*
For actions with no corresponding templates, render
`head :no_content`
instead of raising an error. This allows for slimmer API controller
methods that simply work, without needing further instructions.
See #19036.
*Stephen Bussey*
*
Provide friendlier access to request variants.
request.variant = :phone
...
...
actionpack/lib/action_controller/metal/implicit_render.rb
浏览文件 @
0de4a23d
...
...
@@ -7,7 +7,12 @@ def send_action(method, *args)
end
def
default_render
(
*
args
)
render
(
*
args
)
if
template_exists?
(
action_name
.
to_s
,
_prefixes
,
variants:
request
.
variant
)
render
(
*
args
)
else
logger
.
info
"No template found for
#{
self
.
class
.
name
}
\#
#{
action_name
}
, rendering head :no_content"
head
:no_content
end
end
def
method_for_action
(
action_name
)
...
...
actionpack/test/controller/mime/respond_to_test.rb
浏览文件 @
0de4a23d
...
...
@@ -608,19 +608,29 @@ def test_invalid_format
end
def
test_invalid_variant
logger
=
ActiveSupport
::
LogSubscriber
::
TestHelper
::
MockLogger
.
new
old_logger
,
ActionController
::
Base
.
logger
=
ActionController
::
Base
.
logger
,
logger
@request
.
variant
=
:invalid
assert_raises
(
ActionView
::
MissingTemplate
)
do
get
:variant_with_implicit_rendering
end
get
:variant_with_implicit_rendering
assert_response
:no_content
assert_equal
1
,
logger
.
logged
(
:info
).
select
{
|
s
|
s
=~
/No template found/
}.
size
,
"Implicit head :no_content not logged"
ensure
ActionController
::
Base
.
logger
=
old_logger
end
def
test_variant_not_set_regular_template_missing
assert_raises
(
ActionView
::
MissingTemplate
)
do
get
:variant_with_implicit_rendering
end
get
:variant_with_implicit_rendering
assert_response
:no_content
end
def
test_variant_with_implicit_rendering
@request
.
variant
=
:implicit
get
:variant_with_implicit_rendering
assert_response
:no_content
end
def
test_variant_with_implicit_template_rendering
@request
.
variant
=
:mobile
get
:variant_with_implicit_rendering
assert_equal
"text/html"
,
@response
.
content_type
...
...
actionview/lib/action_view/lookup_context.rb
浏览文件 @
0de4a23d
...
...
@@ -126,7 +126,7 @@ def find_all(name, prefixes = [], partial = false, keys = [], options = {})
@view_paths
.
find_all
(
*
args_for_lookup
(
name
,
prefixes
,
partial
,
keys
,
options
))
end
def
exists?
(
name
,
prefixes
=
[],
partial
=
false
,
keys
=
[],
options
=
{}
)
def
exists?
(
name
,
prefixes
=
[],
partial
=
false
,
keys
=
[],
**
options
)
@view_paths
.
exists?
(
*
args_for_lookup
(
name
,
prefixes
,
partial
,
keys
,
options
))
end
alias
:template_exists?
:exists?
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录