Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
f63d35fb
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,发现更多精彩内容 >>
提交
f63d35fb
编写于
9月 29, 2010
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Ensure that named routes do not overwrite previously defined routes.
上级
b1ae7962
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
31 addition
and
10 deletion
+31
-10
actionpack/lib/action_dispatch/routing/mapper.rb
actionpack/lib/action_dispatch/routing/mapper.rb
+13
-10
actionpack/test/dispatch/routing_test.rb
actionpack/test/dispatch/routing_test.rb
+18
-0
未找到文件。
actionpack/lib/action_dispatch/routing/mapper.rb
浏览文件 @
f63d35fb
...
...
@@ -62,7 +62,6 @@ def normalize_options!
if
using_match_shorthand?
(
path_without_format
,
@options
)
to_shorthand
=
@options
[
:to
].
blank?
@options
[
:to
]
||=
path_without_format
[
1
..-
1
].
sub
(
%r{/([^/]*)$}
,
'#\1'
)
@options
[
:as
]
||=
Mapper
.
normalize_name
(
path_without_format
)
end
@options
.
merge!
(
default_controller_and_action
(
to_shorthand
))
...
...
@@ -924,9 +923,14 @@ def match(*args)
if
action
.
to_s
=~
/^[\w\/]+$/
options
[
:action
]
||=
action
unless
action
.
to_s
.
include?
(
"/"
)
options
[
:as
]
=
name_for_action
(
action
,
options
[
:as
])
else
options
[
:as
]
=
name_for_action
(
options
[
:as
])
action
=
nil
end
if
options
.
key?
(
:as
)
&&
!
options
[
:as
]
options
.
delete
(
:as
)
else
options
[
:as
]
=
name_for_action
(
options
[
:as
],
action
)
end
super
(
path
,
options
)
...
...
@@ -1092,18 +1096,16 @@ def action_path(name, path = nil)
path
||
@scope
[
:path_names
][
name
.
to_sym
]
||
name
.
to_s
end
def
prefix_name_for_action
(
a
ction
,
as
)
if
as
.
present?
def
prefix_name_for_action
(
a
s
,
action
)
if
as
as
.
to_s
elsif
as
nil
elsif
!
canonical_action?
(
action
,
@scope
[
:scope_level
])
action
.
to_s
end
end
def
name_for_action
(
a
ction
,
as
=
nil
)
prefix
=
prefix_name_for_action
(
a
ction
,
as
)
def
name_for_action
(
a
s
,
action
)
prefix
=
prefix_name_for_action
(
a
s
,
action
)
prefix
=
Mapper
.
normalize_name
(
prefix
)
if
prefix
name_prefix
=
@scope
[
:as
]
...
...
@@ -1127,7 +1129,8 @@ def name_for_action(action, as=nil)
[
name_prefix
,
member_name
,
prefix
]
end
name
.
select
(
&
:present?
).
join
(
"_"
).
presence
candidate
=
name
.
select
(
&
:present?
).
join
(
"_"
).
presence
candidate
unless
as
.
nil?
&&
@set
.
routes
.
map
(
&
:name
).
include?
(
candidate
)
end
end
...
...
actionpack/test/dispatch/routing_test.rb
浏览文件 @
f63d35fb
...
...
@@ -442,6 +442,15 @@ def self.matches?(request)
get
:preview
,
:on
=>
:member
end
scope
:as
=>
"routes"
do
get
"/c/:id"
,
:as
=>
:collision
,
:to
=>
"collision#show"
get
"/collision"
,
:to
=>
"collision#show"
get
"/no_collision"
,
:to
=>
"collision#show"
,
:as
=>
nil
get
"/fc/:id"
,
:as
=>
:forced_collision
,
:to
=>
"forced_collision#show"
get
"/forced_collision"
,
:as
=>
:forced_collision
,
:to
=>
"forced_collision#show"
end
match
'/purchases/:token/:filename'
,
:to
=>
'purchases#fetch'
,
:token
=>
/[[:alnum:]]{10}/
,
...
...
@@ -2120,6 +2129,15 @@ def test_nested_resource_constraints
assert_raises
(
ActionController
::
RoutingError
){
list_todo_path
(
:list_id
=>
'2'
,
:id
=>
'1'
)
}
end
def
test_named_routes_collision_is_avoided_unless_explicitly_given_as
assert_equal
"/c/1"
,
routes_collision_path
(
1
)
assert_equal
"/forced_collision"
,
routes_forced_collision_path
end
def
test_explicitly_avoiding_the_named_route
assert
!
respond_to?
(
:routes_no_collision_path
)
end
def
test_controller_name_with_leading_slash_raise_error
assert_raise
(
ArgumentError
)
do
self
.
class
.
stub_controllers
do
|
routes
|
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录