Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
684a6b3c
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,发现更多精彩内容 >>
提交
684a6b3c
编写于
8月 29, 2009
作者:
J
José Valim
提交者:
Yehuda Katz
8月 29, 2009
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Attempt to render the template inside the responder, so it can be used for caching and pagination.
Signed-off-by:
N
Yehuda Katz
<
wycats@gmail.com
>
上级
dbf20c2d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
37 addition
and
26 deletion
+37
-26
actionpack/lib/action_controller/metal/mime_responds.rb
actionpack/lib/action_controller/metal/mime_responds.rb
+28
-21
actionpack/lib/action_controller/metal/responder.rb
actionpack/lib/action_controller/metal/responder.rb
+9
-5
未找到文件。
actionpack/lib/action_controller/metal/mime_responds.rb
浏览文件 @
684a6b3c
...
@@ -178,23 +178,7 @@ def clear_respond_to
...
@@ -178,23 +178,7 @@ def clear_respond_to
#
#
def
respond_to
(
*
mimes
,
&
block
)
def
respond_to
(
*
mimes
,
&
block
)
raise
ArgumentError
,
"respond_to takes either types or a block, never both"
if
mimes
.
any?
&&
block_given?
raise
ArgumentError
,
"respond_to takes either types or a block, never both"
if
mimes
.
any?
&&
block_given?
collect_mimes_for_render
(
mimes
,
block
){
default_render
}
collector
=
Collector
.
new
mimes
=
collect_mimes_from_class_level
if
mimes
.
empty?
mimes
.
each
{
|
mime
|
collector
.
send
(
mime
)
}
block
.
call
(
collector
)
if
block_given?
if
format
=
request
.
negotiate_mime
(
collector
.
order
)
self
.
formats
=
[
format
.
to_sym
]
if
response
=
collector
.
response_for
(
format
)
response
.
call
else
default_render
end
else
head
:not_acceptable
end
end
end
# respond_with wraps a resource around a responder for default representation.
# respond_with wraps a resource around a responder for default representation.
...
@@ -227,10 +211,10 @@ def respond_to(*mimes, &block)
...
@@ -227,10 +211,10 @@ def respond_to(*mimes, &block)
# a proc to it.
# a proc to it.
#
#
def
respond_with
(
*
resources
,
&
block
)
def
respond_with
(
*
resources
,
&
block
)
respond_to
(
&
block
)
collect_mimes_for_render
([],
block
)
do
rescue
ActionView
::
MissingTemplate
options
=
resources
.
extract_options!
options
=
resources
.
extract_options!
(
options
.
delete
(
:responder
)
||
responder
).
call
(
self
,
resources
,
options
)
(
options
.
delete
(
:responder
)
||
responder
).
call
(
self
,
resources
,
options
)
end
end
end
def
responder
def
responder
...
@@ -258,6 +242,29 @@ def collect_mimes_from_class_level #:nodoc:
...
@@ -258,6 +242,29 @@ def collect_mimes_from_class_level #:nodoc:
end
end
end
end
# Receives a collection of mimes and a block with formats and initialize a
# collector. If a response was added to the collector, uses it to satisfy
# the request, otherwise yields the block given.
#
def
collect_mimes_for_render
(
mimes
,
formats
)
collector
=
Collector
.
new
mimes
=
collect_mimes_from_class_level
if
mimes
.
empty?
mimes
.
each
{
|
mime
|
collector
.
send
(
mime
)
}
formats
.
call
(
collector
)
if
formats
if
format
=
request
.
negotiate_mime
(
collector
.
order
)
self
.
formats
=
[
format
.
to_sym
]
if
response
=
collector
.
response_for
(
format
)
response
.
call
else
yield
end
else
head
:not_acceptable
end
end
class
Collector
#:nodoc:
class
Collector
#:nodoc:
attr_accessor
:order
attr_accessor
:order
...
...
actionpack/lib/action_controller/metal/responder.rb
浏览文件 @
684a6b3c
...
@@ -109,8 +109,10 @@ def self.call(*args)
...
@@ -109,8 +109,10 @@ def self.call(*args)
# template.
# template.
#
#
def
to_html
def
to_html
render
rescue
ActionView
::
MissingTemplate
if
get?
if
get?
r
ender
r
aise
elsif
has_errors?
elsif
has_errors?
render
:action
=>
default_action
render
:action
=>
default_action
else
else
...
@@ -118,12 +120,14 @@ def to_html
...
@@ -118,12 +120,14 @@ def to_html
end
end
end
end
# All others formats
try to render the resource given instead. For this
# All others formats
follow the procedure below. First we try to render a
#
purpose a helper called display as a shortcut to render a resource with
#
template, if the template is not available, we verify if the resource
#
the current forma
t.
#
responds to :to_format and display i
t.
#
#
def
to_format
def
to_format
return
render
unless
resourceful?
render
rescue
ActionView
::
MissingTemplate
raise
unless
resourceful?
if
get?
if
get?
display
resource
display
resource
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录