Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
47a27e89
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,发现更多精彩内容 >>
提交
47a27e89
编写于
2月 23, 2016
作者:
A
Andrew White
提交者:
Andrew White
2月 21, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename url_helper to direct
上级
ce7d5fb2
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
23 addition
and
23 deletion
+23
-23
actionpack/lib/action_dispatch/routing/mapper.rb
actionpack/lib/action_dispatch/routing/mapper.rb
+7
-7
actionpack/test/dispatch/routing/custom_url_helpers_test.rb
actionpack/test/dispatch/routing/custom_url_helpers_test.rb
+12
-12
railties/test/application/routing_test.rb
railties/test/application/routing_test.rb
+4
-4
未找到文件。
actionpack/lib/action_dispatch/routing/mapper.rb
浏览文件 @
47a27e89
...
...
@@ -2020,20 +2020,20 @@ def concerns(*args)
end
end
module
UrlHelper
s
module
DirectUrl
s
# Define a custom url helper that will be added to the url helpers
# module. This allows you override and/or replace the default behavior
# of routing helpers, e.g:
#
#
url_helper
:homepage do
#
direct
:homepage do
# "http://www.rubyonrails.org"
# end
#
#
url_helper
:commentable do |model|
#
direct
:commentable do |model|
# [ model, anchor: model.dom_id ]
# end
#
#
url_helper
:main do
#
direct
:main do
# { controller: 'pages', action: 'index', subdomain: 'www' }
# end
#
...
...
@@ -2049,13 +2049,13 @@ module UrlHelpers
# You can also specify default options that will be passed through to
# your url helper definition, e.g:
#
#
url_helper
:browse, page: 1, size: 10 do |options|
#
direct
:browse, page: 1, size: 10 do |options|
# [ :products, options.merge(params.permit(:page, :size)) ]
# end
#
# NOTE: It is the url helper's responsibility to return the correct
# set of options to be passed to the `url_for` call.
def
url_helper
(
name
,
options
=
{},
&
block
)
def
direct
(
name
,
options
=
{},
&
block
)
@set
.
add_url_helper
(
name
,
options
,
&
block
)
end
end
...
...
@@ -2153,7 +2153,7 @@ def initialize(set) #:nodoc:
include
Scoping
include
Concerns
include
Resources
include
UrlHelper
s
include
DirectUrl
s
end
end
end
actionpack/test/dispatch/routing/custom_url_helpers_test.rb
浏览文件 @
47a27e89
...
...
@@ -30,14 +30,14 @@ class Product < Linkable; end
get
"/dashboard"
,
to:
"dashboard#index"
end
url_helper
(
:website
)
{
"http://www.rubyonrails.org"
}
url_helper
(
:linkable
)
{
|
linkable
|
[
:"
#{
linkable
.
linkable_type
}
"
,
{
id:
linkable
.
id
}]
}
url_helper
(
:params
)
{
|
params
|
params
}
url_helper
(
:symbol
)
{
:basket
}
url_helper
(
:hash
)
{
{
controller:
"basket"
,
action:
"show"
}
}
url_helper
(
:array
)
{
[
:admin
,
:dashboard
]
}
url_helper
(
:options
)
{
|
options
|
[
:products
,
options
]
}
url_helper
(
:defaults
,
size:
10
)
{
|
options
|
[
:products
,
options
]
}
direct
(
:website
)
{
"http://www.rubyonrails.org"
}
direct
(
:linkable
)
{
|
linkable
|
[
:"
#{
linkable
.
linkable_type
}
"
,
{
id:
linkable
.
id
}]
}
direct
(
:params
)
{
|
params
|
params
}
direct
(
:symbol
)
{
:basket
}
direct
(
:hash
)
{
{
controller:
"basket"
,
action:
"show"
}
}
direct
(
:array
)
{
[
:admin
,
:dashboard
]
}
direct
(
:options
)
{
|
options
|
[
:products
,
options
]
}
direct
(
:defaults
,
size:
10
)
{
|
options
|
[
:products
,
options
]
}
end
APP
=
build_app
Routes
...
...
@@ -57,7 +57,7 @@ def setup
@safe_params
=
ActionController
::
Parameters
.
new
(
@path_params
).
permit
(
:controller
,
:action
)
end
def
test_
custom_path_helper
def
test_
direct_paths
assert_equal
"http://www.rubyonrails.org"
,
website_path
assert_equal
"http://www.rubyonrails.org"
,
Routes
.
url_helpers
.
website_path
...
...
@@ -88,7 +88,7 @@ def test_custom_path_helper
assert_equal
"/products?size=20"
,
Routes
.
url_helpers
.
defaults_path
(
size:
20
)
end
def
test_
custom_url_helper
def
test_
direct_urls
assert_equal
"http://www.rubyonrails.org"
,
website_url
assert_equal
"http://www.rubyonrails.org"
,
Routes
.
url_helpers
.
website_url
...
...
@@ -108,8 +108,8 @@ def test_custom_url_helper
assert_equal
"http://www.example.com/basket"
,
Routes
.
url_helpers
.
symbol_url
assert_equal
"http://www.example.com/basket"
,
hash_url
assert_equal
"http://www.example.com/basket"
,
Routes
.
url_helpers
.
hash_url
assert_equal
"
/admin/dashboard"
,
array_path
assert_equal
"
/admin/dashboard"
,
Routes
.
url_helpers
.
array_path
assert_equal
"
http://www.example.com/admin/dashboard"
,
array_url
assert_equal
"
http://www.example.com/admin/dashboard"
,
Routes
.
url_helpers
.
array_url
assert_equal
"http://www.example.com/products?page=2"
,
options_url
(
page:
2
)
assert_equal
"http://www.example.com/products?page=2"
,
Routes
.
url_helpers
.
options_url
(
page:
2
)
...
...
railties/test/application/routing_test.rb
浏览文件 @
47a27e89
...
...
@@ -289,7 +289,7 @@ def custom
get 'foo', to: 'foo#bar'
get 'custom', to: 'foo#custom'
url_helper
(:custom) { "http://www.microsoft.com" }
direct
(:custom) { "http://www.microsoft.com" }
end
RUBY
...
...
@@ -306,7 +306,7 @@ def custom
get 'foo', to: 'foo#baz'
get 'custom', to: 'foo#custom'
url_helper
(:custom) { "http://www.apple.com" }
direct
(:custom) { "http://www.apple.com" }
end
RUBY
...
...
@@ -466,7 +466,7 @@ def index
app_file
"config/routes.rb"
,
<<-
RUBY
Rails.application.routes.draw do
get ':locale/foo', to: 'foo#index', as: 'foo'
url_helper
(:microsoft) { 'http://www.microsoft.com' }
direct
(:microsoft) { 'http://www.microsoft.com' }
end
RUBY
...
...
@@ -478,7 +478,7 @@ def index
app_file
"config/routes.rb"
,
<<-
RUBY
Rails.application.routes.draw do
get ':locale/bar', to: 'bar#index', as: 'foo'
url_helper
(:apple) { 'http://www.apple.com' }
direct
(:apple) { 'http://www.apple.com' }
end
RUBY
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录