Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
7fe26ad8
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,发现更多精彩内容 >>
提交
7fe26ad8
编写于
7月 01, 2017
作者:
M
Matthew Draper
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #29644 from wilson/unify-route-helper-visibility
Properly register "custom" URL helpers as named helpers.
上级
3acc3767
250bc332
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
17 addition
and
18 deletion
+17
-18
actionpack/lib/action_dispatch/routing/route_set.rb
actionpack/lib/action_dispatch/routing/route_set.rb
+11
-18
actionpack/test/dispatch/routing/custom_url_helpers_test.rb
actionpack/test/dispatch/routing/custom_url_helpers_test.rb
+6
-0
未找到文件。
actionpack/lib/action_dispatch/routing/route_set.rb
浏览文件 @
7fe26ad8
...
...
@@ -73,7 +73,6 @@ def initialize
@routes
=
{}
@path_helpers
=
Set
.
new
@url_helpers
=
Set
.
new
@custom_helpers
=
Set
.
new
@url_helpers_module
=
Module
.
new
@path_helpers_module
=
Module
.
new
end
...
...
@@ -96,23 +95,9 @@ def clear!
@url_helpers_module
.
send
:remove_method
,
helper
end
@custom_helpers
.
each
do
|
helper
|
path_name
=
:"
#{
helper
}
_path"
url_name
=
:"
#{
helper
}
_url"
if
@path_helpers_module
.
method_defined?
(
path_name
)
@path_helpers_module
.
send
:remove_method
,
path_name
end
if
@url_helpers_module
.
method_defined?
(
url_name
)
@url_helpers_module
.
send
:remove_method
,
url_name
end
end
@routes
.
clear
@path_helpers
.
clear
@url_helpers
.
clear
@custom_helpers
.
clear
end
def
add
(
name
,
route
)
...
...
@@ -158,21 +143,29 @@ def length
routes
.
length
end
# Given a +name+, defines name_path and name_url helpers.
# Used by 'direct', 'resolve', and 'polymorphic' route helpers.
def
add_url_helper
(
name
,
defaults
,
&
block
)
@custom_helpers
<<
name
helper
=
CustomUrlHelper
.
new
(
name
,
defaults
,
&
block
)
path_name
=
:"
#{
name
}
_path"
url_name
=
:"
#{
name
}
_url"
@path_helpers_module
.
module_eval
do
define_method
(
:"
#{
name
}
_path"
)
do
|*
args
|
define_method
(
path_name
)
do
|*
args
|
helper
.
call
(
self
,
args
,
true
)
end
end
@url_helpers_module
.
module_eval
do
define_method
(
:"
#{
name
}
_url"
)
do
|*
args
|
define_method
(
url_name
)
do
|*
args
|
helper
.
call
(
self
,
args
,
false
)
end
end
@path_helpers
<<
path_name
@url_helpers
<<
url_name
self
end
class
UrlHelper
...
...
actionpack/test/dispatch/routing/custom_url_helpers_test.rb
浏览文件 @
7fe26ad8
...
...
@@ -322,4 +322,10 @@ def test_defining_resolve_inside_a_scope_raises_runtime_error
end
end
end
def
test_defining_direct_url_registers_helper_method
assert_equal
"http://www.example.com/basket"
,
Routes
.
url_helpers
.
symbol_url
assert_equal
true
,
Routes
.
named_routes
.
route_defined?
(
:symbol_url
),
"'symbol_url' named helper not found"
assert_equal
true
,
Routes
.
named_routes
.
route_defined?
(
:symbol_path
),
"'symbol_path' named helper not found"
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录