Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
4f9047ec
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,发现更多精彩内容 >>
提交
4f9047ec
编写于
8月 13, 2009
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Ensure collections are not treated as nested resources.
上级
5f7cfffc
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
36 addition
and
18 deletion
+36
-18
actionpack/lib/action_controller/metal/mime_responds.rb
actionpack/lib/action_controller/metal/mime_responds.rb
+3
-2
actionpack/lib/action_controller/metal/responder.rb
actionpack/lib/action_controller/metal/responder.rb
+5
-5
actionpack/test/controller/mime_responds_test.rb
actionpack/test/controller/mime_responds_test.rb
+20
-7
actionpack/test/lib/controller/fake_models.rb
actionpack/test/lib/controller/fake_models.rb
+8
-4
未找到文件。
actionpack/lib/action_controller/metal/mime_responds.rb
浏览文件 @
4f9047ec
...
...
@@ -226,10 +226,11 @@ def respond_to(*mimes, &block)
# is quite simple (it just needs to respond to call), you can even give
# a proc to it.
#
def
respond_with
(
resource
,
options
=
{}
,
&
block
)
def
respond_with
(
*
resources
,
&
block
)
respond_to
(
&
block
)
rescue
ActionView
::
MissingTemplate
(
options
.
delete
(
:responder
)
||
responder
).
call
(
self
,
resource
,
options
)
options
=
resources
.
extract_options!
(
options
.
delete
(
:responder
)
||
responder
).
call
(
self
,
resources
,
options
)
end
def
responder
...
...
actionpack/lib/action_controller/metal/responder.rb
浏览文件 @
4f9047ec
...
...
@@ -64,7 +64,7 @@ module ActionController #:nodoc:
# @project = Project.find(params[:project_id])
# @task = @project.comments.build(params[:task])
# flash[:notice] = 'Task was successfully created.' if @task.save
# respond_with(
[@project, @task]
)
# respond_with(
@project, @task
)
# end
#
# Giving an array of resources, you ensure that the responder will redirect to
...
...
@@ -74,19 +74,19 @@ module ActionController #:nodoc:
# polymorphic urls. If a project has one manager which has many tasks, it
# should be invoked as:
#
# respond_with(
[@project, :manager, @task]
)
# respond_with(
@project, :manager, @task
)
#
# Check polymorphic_url documentation for more examples.
#
class
Responder
attr_reader
:controller
,
:request
,
:format
,
:resource
,
:resource_location
,
:options
def
initialize
(
controller
,
resource
,
options
=
{})
def
initialize
(
controller
,
resource
s
,
options
=
{})
@controller
=
controller
@request
=
controller
.
request
@format
=
controller
.
formats
.
first
@resource
=
resource
.
is_a?
(
Array
)
?
resource
.
last
:
resource
@resource_location
=
options
[
:location
]
||
resource
@resource
=
resource
s
.
is_a?
(
Array
)
?
resources
.
last
:
resources
@resource_location
=
options
[
:location
]
||
resource
s
@options
=
options
end
...
...
actionpack/test/controller/mime_responds_test.rb
浏览文件 @
4f9047ec
...
...
@@ -497,8 +497,12 @@ def using_resource
respond_with
(
Customer
.
new
(
"david"
,
13
))
end
def
using_resource_with_collection
respond_with
([
Customer
.
new
(
"david"
,
13
),
Customer
.
new
(
"jamis"
,
9
)])
end
def
using_resource_with_parent
respond_with
(
[
Quiz
::
Store
.
new
(
"developer?"
,
11
),
Customer
.
new
(
"david"
,
13
)]
)
respond_with
(
Quiz
::
Store
.
new
(
"developer?"
,
11
),
Customer
.
new
(
"david"
,
13
)
)
end
def
using_resource_with_status_and_location
...
...
@@ -506,7 +510,7 @@ def using_resource_with_status_and_location
end
def
using_resource_with_responder
responder
=
proc
{
|
c
,
r
,
o
|
c
.
render
:text
=>
"Resource name is
#{
r
.
name
}
"
}
responder
=
proc
{
|
c
,
r
,
o
|
c
.
render
:text
=>
"Resource name is
#{
r
.
first
.
name
}
"
}
respond_with
(
Customer
.
new
(
"david"
,
13
),
:responder
=>
responder
)
end
...
...
@@ -592,7 +596,7 @@ def test_using_resource
@request
.
accept
=
"application/xml"
get
:using_resource
assert_equal
"application/xml"
,
@response
.
content_type
assert_equal
"
XML
"
,
@response
.
body
assert_equal
"
<name>david</name>
"
,
@response
.
body
@request
.
accept
=
"application/json"
assert_raise
ActionView
::
MissingTemplate
do
...
...
@@ -622,7 +626,7 @@ def test_using_resource_for_post_with_xml
post
:using_resource
assert_equal
"application/xml"
,
@response
.
content_type
assert_equal
201
,
@response
.
status
assert_equal
"
XML
"
,
@response
.
body
assert_equal
"
<name>david</name>
"
,
@response
.
body
assert_equal
"http://www.example.com/customers/13"
,
@response
.
location
errors
=
{
:name
=>
:invalid
}
...
...
@@ -689,7 +693,7 @@ def test_using_resource_with_parent_for_get
get
:using_resource_with_parent
assert_equal
"application/xml"
,
@response
.
content_type
assert_equal
200
,
@response
.
status
assert_equal
"
XML
"
,
@response
.
body
assert_equal
"
<name>david</name>
"
,
@response
.
body
end
def
test_using_resource_with_parent_for_post
...
...
@@ -698,7 +702,7 @@ def test_using_resource_with_parent_for_post
post
:using_resource_with_parent
assert_equal
"application/xml"
,
@response
.
content_type
assert_equal
201
,
@response
.
status
assert_equal
"
XML
"
,
@response
.
body
assert_equal
"
<name>david</name>
"
,
@response
.
body
assert_equal
"http://www.example.com/quiz_stores/11/customers/13"
,
@response
.
location
errors
=
{
:name
=>
:invalid
}
...
...
@@ -710,6 +714,15 @@ def test_using_resource_with_parent_for_post
assert_nil
@response
.
location
end
def
test_using_resource_with_collection
@request
.
accept
=
"application/xml"
get
:using_resource_with_collection
assert_equal
"application/xml"
,
@response
.
content_type
assert_equal
200
,
@response
.
status
assert_match
/<name>david<\/name>/
,
@response
.
body
assert_match
/<name>jamis<\/name>/
,
@response
.
body
end
def
test_clear_respond_to
@controller
=
InheritedRespondWithController
.
new
@request
.
accept
=
"text/html"
...
...
@@ -722,7 +735,7 @@ def test_first_in_respond_to_has_higher_priority
@request
.
accept
=
"*/*"
get
:index
assert_equal
"application/xml"
,
@response
.
content_type
assert_equal
"
XML
"
,
@response
.
body
assert_equal
"
<name>david</name>
"
,
@response
.
body
end
def
test_no_double_render_is_raised
...
...
actionpack/test/lib/controller/fake_models.rb
浏览文件 @
4f9047ec
...
...
@@ -10,12 +10,16 @@ def to_param
id
.
to_s
end
def
to_xml
"XML"
def
to_xml
(
options
=
{})
if
options
[
:builder
]
options
[
:builder
].
name
name
else
"<name>
#{
name
}
</name>"
end
end
def
to_js
"
JS
"
def
to_js
(
options
=
{})
"
name:
#{
name
.
inspect
}
"
end
def
errors
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录