Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
643cac08
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,发现更多精彩内容 >>
未验证
提交
643cac08
编写于
4月 24, 2016
作者:
J
Jeremy Daer
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #23103 from rails/refactor-handling-of-action-default
Refactor handling of :action default in routing
上级
edc2b771
8ca8a2d7
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
73 addition
and
33 deletion
+73
-33
actionpack/CHANGELOG.md
actionpack/CHANGELOG.md
+6
-1
actionpack/lib/action_dispatch/journey/formatter.rb
actionpack/lib/action_dispatch/journey/formatter.rb
+7
-2
actionpack/lib/action_dispatch/routing/inspector.rb
actionpack/lib/action_dispatch/routing/inspector.rb
+2
-2
actionpack/lib/action_dispatch/routing/mapper.rb
actionpack/lib/action_dispatch/routing/mapper.rb
+4
-0
actionpack/lib/action_dispatch/routing/route_set.rb
actionpack/lib/action_dispatch/routing/route_set.rb
+0
-14
actionpack/test/controller/routing_test.rb
actionpack/test/controller/routing_test.rb
+2
-2
actionpack/test/dispatch/routing/inspector_test.rb
actionpack/test/dispatch/routing/inspector_test.rb
+1
-1
actionpack/test/dispatch/routing_test.rb
actionpack/test/dispatch/routing_test.rb
+51
-11
未找到文件。
actionpack/CHANGELOG.md
浏览文件 @
643cac08
*
Routing: Refactor
`:action`
default handling to ensure that path
parameters are not mutated during route generation.
*Andrew White*
*
Add extension synonyms
`yml`
and
`yaml`
for MIME type
`application/x-yaml`
.
*bogdanvlviv*
*bogdanvlviv*
*
Adds support for including ActionController::Cookies in API controllers.
Previously, including the module would raise when trying to define
...
...
actionpack/lib/action_dispatch/journey/formatter.rb
浏览文件 @
643cac08
...
...
@@ -32,8 +32,13 @@ def generate(name, options, path_parameters, parameterize = nil)
defaults
=
route
.
defaults
required_parts
=
route
.
required_parts
parameterized_parts
.
keep_if
do
|
key
,
value
|
(
defaults
[
key
].
nil?
&&
value
.
present?
)
||
value
.
to_s
!=
defaults
[
key
].
to_s
||
required_parts
.
include?
(
key
)
route
.
parts
.
reverse_each
do
|
key
|
break
if
defaults
[
key
].
nil?
&&
parameterized_parts
[
key
].
present?
break
if
parameterized_parts
[
key
].
to_s
!=
defaults
[
key
].
to_s
break
if
required_parts
.
include?
(
key
)
parameterized_parts
.
delete
(
key
)
end
return
[
route
.
format
(
parameterized_parts
),
params
]
...
...
actionpack/lib/action_dispatch/routing/inspector.rb
浏览文件 @
643cac08
...
...
@@ -33,11 +33,11 @@ def reqs
end
def
controller
requirements
[
:controller
]
||
':controller'
parts
.
include?
(
:controller
)
?
':controller'
:
requirements
[
:controller
]
end
def
action
requirements
[
:action
]
||
':action'
parts
.
include?
(
:action
)
?
':action'
:
requirements
[
:action
]
end
def
internal?
...
...
actionpack/lib/action_dispatch/routing/mapper.rb
浏览文件 @
643cac08
...
...
@@ -137,6 +137,10 @@ def initialize(set, ast, defaults, controller, default_action, modyoule, to, for
@conditions
=
Hash
[
conditions
]
@defaults
=
formats
[
:defaults
].
merge
(
@defaults
).
merge
(
normalize_defaults
(
options
))
if
path_params
.
include?
(
:action
)
&&
!
@requirements
.
key?
(
:action
)
@defaults
[
:action
]
||=
'index'
end
@required_defaults
=
(
split_options
[
:required_defaults
]
||
[]).
map
(
&
:first
)
end
...
...
actionpack/lib/action_dispatch/routing/route_set.rb
浏览文件 @
643cac08
...
...
@@ -548,12 +548,10 @@ def initialize(named_route, options, recall, set)
@recall
=
recall
@set
=
set
normalize_recall!
normalize_options!
normalize_controller_action_id!
use_relative_controller!
normalize_controller!
normalize_action!
end
def
controller
...
...
@@ -572,11 +570,6 @@ def use_recall_for(key)
end
end
# Set 'index' as default action for recall
def
normalize_recall!
@recall
[
:action
]
||=
'index'
end
def
normalize_options!
# If an explicit :controller was given, always make :action explicit
# too, so that action expiry works as expected for things like
...
...
@@ -630,13 +623,6 @@ def normalize_controller!
end
end
# Move 'index' action from options to recall
def
normalize_action!
if
@options
[
:action
]
==
'index'
.
freeze
@recall
[
:action
]
=
@options
.
delete
(
:action
)
end
end
# Generates a path from routes, returns [path, params].
# If no route is generated the formatter will raise ActionController::UrlGenerationError
def
generate
...
...
actionpack/test/controller/routing_test.rb
浏览文件 @
643cac08
...
...
@@ -2064,11 +2064,11 @@ def test_generate_extras
def
test_extras
params
=
{
:controller
=>
'people'
}
assert_equal
[],
@routes
.
extra_keys
(
params
)
assert_equal
({
:controller
=>
'people'
},
params
)
assert_equal
({
:controller
=>
'people'
,
:action
=>
'index'
},
params
)
params
=
{
:controller
=>
'people'
,
:foo
=>
'bar'
}
assert_equal
[
:foo
],
@routes
.
extra_keys
(
params
)
assert_equal
({
:controller
=>
'people'
,
:foo
=>
'bar'
},
params
)
assert_equal
({
:controller
=>
'people'
,
:
action
=>
'index'
,
:
foo
=>
'bar'
},
params
)
params
=
{
:controller
=>
'people'
,
:action
=>
'create'
,
:person
=>
{
:name
=>
'Josh'
}}
assert_equal
[
:person
],
@routes
.
extra_keys
(
params
)
...
...
actionpack/test/dispatch/routing/inspector_test.rb
浏览文件 @
643cac08
...
...
@@ -347,7 +347,7 @@ def test_regression_route_with_controller_regexp
end
assert_equal
[
"Prefix Verb URI Pattern Controller#Action"
,
" GET /:controller(/:action)
(?-mix:api
\\
/[^
\\
/]+)
#:action"
],
output
" GET /:controller(/:action)
:controller
#:action"
],
output
end
def
test_inspect_routes_shows_resources_route_when_assets_disabled
...
...
actionpack/test/dispatch/routing_test.rb
浏览文件 @
643cac08
...
...
@@ -3991,16 +3991,6 @@ def app; APP end
end
class
TestMultipleNestedController
<
ActionDispatch
::
IntegrationTest
module
::
Foo
module
Bar
class
BazController
<
ActionController
::
Base
def
index
render
:inline
=>
"<%= url_for :controller => '/pooh', :action => 'index' %>"
end
end
end
end
Routes
=
ActionDispatch
::
Routing
::
RouteSet
.
new
.
tap
do
|
app
|
app
.
draw
do
namespace
:foo
do
...
...
@@ -4012,7 +4002,18 @@ def index
end
end
include
Routes
.
url_helpers
module
::
Foo
module
Bar
class
BazController
<
ActionController
::
Base
include
Routes
.
url_helpers
def
index
render
:inline
=>
"<%= url_for :controller => '/pooh', :action => 'index' %>"
end
end
end
end
APP
=
build_app
Routes
def
app
;
APP
end
...
...
@@ -4755,3 +4756,42 @@ def assert_params(params)
assert_equal
(
params
,
request
.
path_parameters
)
end
end
class
TestPathParameters
<
ActionDispatch
::
IntegrationTest
Routes
=
ActionDispatch
::
Routing
::
RouteSet
.
new
.
tap
do
|
app
|
app
.
draw
do
scope
module:
'test_path_parameters'
do
scope
':locale'
,
locale:
/en|ar/
do
root
to:
'home#index'
get
'/about'
,
to:
'pages#about'
end
end
get
':controller(/:action/(:id))'
end
end
class
HomeController
<
ActionController
::
Base
include
Routes
.
url_helpers
def
index
render
inline:
"<%= root_path %>"
end
end
class
PagesController
<
ActionController
::
Base
include
Routes
.
url_helpers
def
about
render
inline:
"<%= root_path(locale: :ar) %> | <%= url_for(locale: :ar) %>"
end
end
APP
=
build_app
Routes
def
app
;
APP
end
def
test_path_parameters_are_not_mutated
get
'/en/about'
assert_equal
"/ar | /ar/about"
,
@response
.
body
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录