Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
511cef29
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,发现更多精彩内容 >>
提交
511cef29
编写于
12月 08, 2009
作者:
J
Joshua Peek
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Tack format onto resource routes
上级
2be5e088
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
37 addition
and
25 deletion
+37
-25
actionpack/lib/action_dispatch/routing/mapper.rb
actionpack/lib/action_dispatch/routing/mapper.rb
+22
-22
actionpack/test/dispatch/routing_test.rb
actionpack/test/dispatch/routing_test.rb
+15
-3
未找到文件。
actionpack/lib/action_dispatch/routing/mapper.rb
浏览文件 @
511cef29
...
@@ -46,8 +46,8 @@ def match(*args)
...
@@ -46,8 +46,8 @@ def match(*args)
conditions
,
defaults
=
{},
{}
conditions
,
defaults
=
{},
{}
path
=
nil
if
path
==
""
path
=
nil
if
path
==
""
path
=
Rack
::
Mount
::
Utils
.
normalize_path
(
path
)
if
path
path
=
"
#{
@scope
[
:path
]
}#{
path
}
"
if
@scope
[
:path
]
path
=
"
#{
@scope
[
:path
]
}#{
path
}
"
if
@scope
[
:path
]
path
=
Rack
::
Mount
::
Utils
.
normalize_path
(
path
)
if
path
raise
ArgumentError
,
"path is required"
unless
path
raise
ArgumentError
,
"path is required"
unless
path
...
@@ -169,7 +169,7 @@ def scope(*args)
...
@@ -169,7 +169,7 @@ def scope(*args)
if
path
=
options
.
delete
(
:path
)
if
path
=
options
.
delete
(
:path
)
path_set
=
true
path_set
=
true
path
,
@scope
[
:path
]
=
@scope
[
:path
],
"
#{
@scope
[
:path
]
}#{
Rack
::
Mount
::
Utils
.
normalize_path
(
path
)
}
"
path
,
@scope
[
:path
]
=
@scope
[
:path
],
Rack
::
Mount
::
Utils
.
normalize_path
(
@scope
[
:path
].
to_s
+
path
.
to_s
)
else
else
path_set
=
false
path_set
=
false
end
end
...
@@ -214,7 +214,7 @@ def controller(controller)
...
@@ -214,7 +214,7 @@ def controller(controller)
end
end
def
namespace
(
path
)
def
namespace
(
path
)
scope
(
path
.
to_s
)
{
yield
}
scope
(
"/
#{
path
}
"
)
{
yield
}
end
end
def
constraints
(
constraints
=
{})
def
constraints
(
constraints
=
{})
...
@@ -297,16 +297,16 @@ def resource(*resources, &block)
...
@@ -297,16 +297,16 @@ def resource(*resources, &block)
return
self
return
self
end
end
scope
(
:path
=>
resource
.
name
,
:controller
=>
resource
.
controller
)
do
scope
(
:path
=>
"/
#{
resource
.
name
}
"
,
:controller
=>
resource
.
controller
)
do
with_scope_level
(
:resource
,
resource
)
do
with_scope_level
(
:resource
,
resource
)
do
yield
if
block_given?
yield
if
block_given?
get
""
,
:to
=>
:show
,
:as
=>
resource
.
member_name
get
"
(.:format)
"
,
:to
=>
:show
,
:as
=>
resource
.
member_name
post
""
,
:to
=>
:create
post
"
(.:format)
"
,
:to
=>
:create
put
""
,
:to
=>
:update
put
"
(.:format)
"
,
:to
=>
:update
delete
""
,
:to
=>
:destroy
delete
"
(.:format)
"
,
:to
=>
:destroy
get
"
new
"
,
:to
=>
:new
,
:as
=>
"new_
#{
resource
.
singular
}
"
get
"
/new(.:format)
"
,
:to
=>
:new
,
:as
=>
"new_
#{
resource
.
singular
}
"
get
"
edit
"
,
:to
=>
:edit
,
:as
=>
"edit_
#{
resource
.
singular
}
"
get
"
/edit(.:format)
"
,
:to
=>
:edit
,
:as
=>
"edit_
#{
resource
.
singular
}
"
end
end
end
end
...
@@ -331,22 +331,22 @@ def resources(*resources, &block)
...
@@ -331,22 +331,22 @@ def resources(*resources, &block)
return
self
return
self
end
end
scope
(
:path
=>
resource
.
name
,
:controller
=>
resource
.
controller
)
do
scope
(
:path
=>
"/
#{
resource
.
name
}
"
,
:controller
=>
resource
.
controller
)
do
with_scope_level
(
:resources
,
resource
)
do
with_scope_level
(
:resources
,
resource
)
do
yield
if
block_given?
yield
if
block_given?
with_scope_level
(
:collection
)
do
with_scope_level
(
:collection
)
do
get
""
,
:to
=>
:index
,
:as
=>
resource
.
collection_name
get
"
(.:format)
"
,
:to
=>
:index
,
:as
=>
resource
.
collection_name
post
""
,
:to
=>
:create
post
"
(.:format)
"
,
:to
=>
:create
get
"
new
"
,
:to
=>
:new
,
:as
=>
"new_
#{
resource
.
singular
}
"
get
"
/new(.:format)
"
,
:to
=>
:new
,
:as
=>
"new_
#{
resource
.
singular
}
"
end
end
with_scope_level
(
:member
)
do
with_scope_level
(
:member
)
do
scope
(
":id"
)
do
scope
(
"
/
:id"
)
do
get
""
,
:to
=>
:show
,
:as
=>
resource
.
member_name
get
"
(.:format)
"
,
:to
=>
:show
,
:as
=>
resource
.
member_name
put
""
,
:to
=>
:update
put
"
(.:format)
"
,
:to
=>
:update
delete
""
,
:to
=>
:destroy
delete
"
(.:format)
"
,
:to
=>
:destroy
get
"
edit
"
,
:to
=>
:edit
,
:as
=>
"edit_
#{
resource
.
singular
}
"
get
"
/edit(.:format)
"
,
:to
=>
:edit
,
:as
=>
"edit_
#{
resource
.
singular
}
"
end
end
end
end
end
end
...
@@ -373,7 +373,7 @@ def member
...
@@ -373,7 +373,7 @@ def member
end
end
with_scope_level
(
:member
)
do
with_scope_level
(
:member
)
do
scope
(
":id"
,
:name_prefix
=>
parent_resource
.
member_name
,
:as
=>
""
)
do
scope
(
"
/
:id"
,
:name_prefix
=>
parent_resource
.
member_name
,
:as
=>
""
)
do
yield
yield
end
end
end
end
...
@@ -385,7 +385,7 @@ def nested
...
@@ -385,7 +385,7 @@ def nested
end
end
with_scope_level
(
:nested
)
do
with_scope_level
(
:nested
)
do
scope
(
parent_resource
.
id_segment
,
:name_prefix
=>
parent_resource
.
member_name
)
do
scope
(
"/
#{
parent_resource
.
id_segment
}
"
,
:name_prefix
=>
parent_resource
.
member_name
)
do
yield
yield
end
end
end
end
...
@@ -402,7 +402,7 @@ def match(*args)
...
@@ -402,7 +402,7 @@ def match(*args)
if
args
.
first
.
is_a?
(
Symbol
)
if
args
.
first
.
is_a?
(
Symbol
)
begin
begin
old_name_prefix
,
@scope
[
:name_prefix
]
=
@scope
[
:name_prefix
],
"
#{
args
.
first
}
_
#{
@scope
[
:name_prefix
]
}
"
old_name_prefix
,
@scope
[
:name_prefix
]
=
@scope
[
:name_prefix
],
"
#{
args
.
first
}
_
#{
@scope
[
:name_prefix
]
}
"
return
match
(
args
.
first
.
to_s
,
options
.
merge
(
:to
=>
args
.
first
.
to_sym
))
return
match
(
"/
#{
args
.
first
}
(.:format)"
,
options
.
merge
(
:to
=>
args
.
first
.
to_sym
))
ensure
ensure
@scope
[
:name_prefix
]
=
old_name_prefix
@scope
[
:name_prefix
]
=
old_name_prefix
end
end
...
...
actionpack/test/dispatch/routing_test.rb
浏览文件 @
511cef29
...
@@ -95,9 +95,9 @@ def self.matches?(request)
...
@@ -95,9 +95,9 @@ def self.matches?(request)
end
end
controller
:articles
do
controller
:articles
do
scope
'articles'
,
:name_prefix
=>
'article'
do
scope
'
/
articles'
,
:name_prefix
=>
'article'
do
scope
:path
=>
':title'
,
:title
=>
/[a-z]+/
,
:as
=>
:with_title
do
scope
:path
=>
'
/
:title'
,
:title
=>
/[a-z]+/
,
:as
=>
:with_title
do
match
':id'
,
:to
=>
:with_id
match
'
/
:id'
,
:to
=>
:with_id
end
end
end
end
end
end
...
@@ -196,14 +196,26 @@ def test_projects
...
@@ -196,14 +196,26 @@ def test_projects
assert_equal
'projects#index'
,
@response
.
body
assert_equal
'projects#index'
,
@response
.
body
assert_equal
'/projects'
,
projects_path
assert_equal
'/projects'
,
projects_path
get
'/projects.xml'
assert_equal
'projects#index'
,
@response
.
body
assert_equal
'/projects.xml'
,
projects_path
(
:format
=>
'xml'
)
get
'/projects/new'
get
'/projects/new'
assert_equal
'projects#new'
,
@response
.
body
assert_equal
'projects#new'
,
@response
.
body
assert_equal
'/projects/new'
,
new_project_path
assert_equal
'/projects/new'
,
new_project_path
get
'/projects/new.xml'
assert_equal
'projects#new'
,
@response
.
body
assert_equal
'/projects/new.xml'
,
new_project_path
(
:format
=>
'xml'
)
get
'/projects/1'
get
'/projects/1'
assert_equal
'projects#show'
,
@response
.
body
assert_equal
'projects#show'
,
@response
.
body
assert_equal
'/projects/1'
,
project_path
(
:id
=>
'1'
)
assert_equal
'/projects/1'
,
project_path
(
:id
=>
'1'
)
get
'/projects/1.xml'
assert_equal
'projects#show'
,
@response
.
body
assert_equal
'/projects/1.xml'
,
project_path
(
:id
=>
'1'
,
:format
=>
'xml'
)
get
'/projects/1/edit'
get
'/projects/1/edit'
assert_equal
'projects#edit'
,
@response
.
body
assert_equal
'projects#edit'
,
@response
.
body
assert_equal
'/projects/1/edit'
,
edit_project_path
(
:id
=>
'1'
)
assert_equal
'/projects/1/edit'
,
edit_project_path
(
:id
=>
'1'
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录