Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
296b1eef
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,发现更多精彩内容 >>
提交
296b1eef
编写于
7月 16, 2011
作者:
S
Santiago Pastorino
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2082 from htanata/rake_routes_formatting
Better formatting of rake routes (issue #1991)
上级
e98d7477
7b619f1d
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
107 addition
and
15 deletion
+107
-15
actionpack/lib/action_dispatch/routing/mapper.rb
actionpack/lib/action_dispatch/routing/mapper.rb
+7
-7
railties/guides/source/routing.textile
railties/guides/source/routing.textile
+4
-4
railties/lib/rails/tasks/routes.rake
railties/lib/rails/tasks/routes.rake
+10
-2
railties/test/application/rake_test.rb
railties/test/application/rake_test.rb
+86
-2
未找到文件。
actionpack/lib/action_dispatch/routing/mapper.rb
浏览文件 @
296b1eef
...
...
@@ -659,13 +659,13 @@ def controller(controller, options={})
#
# This generates the following routes:
#
# admin_posts GET /admin/posts(.:format)
{:action=>"index", :controller=>"admin/posts"}
# admin_posts POST /admin/posts(.:format)
{:action=>"create", :controller=>"admin/posts"}
# new_admin_post GET /admin/posts/new(.:format)
{:action=>"new", :controller=>"admin/posts"}
# edit_admin_post GET /admin/posts/:id/edit(.:format)
{:action=>"edit", :controller=>"admin/posts"}
# admin_post GET /admin/posts/:id(.:format)
{:action=>"show", :controller=>"admin/posts"}
# admin_post PUT /admin/posts/:id(.:format)
{:action=>"update", :controller=>"admin/posts"}
# admin_post DELETE /admin/posts/:id(.:format)
{:action=>"destroy", :controller=>"admin/posts"}
# admin_posts GET /admin/posts(.:format)
admin/posts#index
# admin_posts POST /admin/posts(.:format)
admin/posts#create
# new_admin_post GET /admin/posts/new(.:format)
admin/posts#new
# edit_admin_post GET /admin/posts/:id/edit(.:format)
admin/posts#edit
# admin_post GET /admin/posts/:id(.:format)
admin/posts#show
# admin_post PUT /admin/posts/:id(.:format)
admin/posts#update
# admin_post DELETE /admin/posts/:id(.:format)
admin/posts#destroy
#
# === Options
#
...
...
railties/guides/source/routing.textile
浏览文件 @
296b1eef
...
...
@@ -823,10 +823,10 @@ If you want a complete list of all of the available routes in your application,
For example, here's a small section of the +rake routes+ output for a RESTful route:
<pre>
users GET /users {:controller=>"users", :action=>"index"}
formatted_users GET /users.:format {:controller=>"users", :action=>"index"}
POST /users {:controller=>"users", :action=>"create"}
POST /users.:format {:controller=>"users", :action=>"create"}
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
</pre>
You may restrict the listing to the routes that map to a particular controller setting the +CONTROLLER+ environment variable:
...
...
railties/lib/rails/tasks/routes.rake
浏览文件 @
296b1eef
...
...
@@ -10,8 +10,16 @@ task :routes => :environment do
routes
=
all_routes
.
collect
do
|
route
|
reqs
=
route
.
requirements
.
dup
reqs
[
:to
]
=
route
.
app
unless
route
.
app
.
class
.
name
.
to_s
=~
/^ActionDispatch::Routing/
reqs
=
reqs
.
empty?
?
""
:
reqs
.
inspect
rack_app
=
route
.
app
unless
route
.
app
.
class
.
name
.
to_s
=~
/^ActionDispatch::Routing/
endpoint
=
rack_app
?
rack_app
.
inspect
:
"
#{
reqs
[
:controller
]
}
#
#{
reqs
[
:action
]
}
"
constraints
=
reqs
.
except
(
:controller
,
:action
)
reqs
=
endpoint
==
'#'
?
''
:
endpoint
unless
constraints
.
empty?
reqs
=
reqs
.
empty?
?
constraints
.
inspect
:
"
#{
reqs
}
#{
constraints
.
inspect
}
"
end
{
:name
=>
route
.
name
.
to_s
,
:verb
=>
route
.
verb
.
to_s
,
:path
=>
route
.
path
,
:reqs
=>
reqs
}
end
...
...
railties/test/application/rake_test.rb
浏览文件 @
296b1eef
...
...
@@ -91,7 +91,7 @@ def test_rake_routes_output_strips_anchors_from_http_verbs
get '/cart', :to => 'cart#show'
end
RUBY
assert_
match
'cart GET /cart(.:format)'
,
Dir
.
chdir
(
app_path
){
`rake routes`
}
assert_
equal
"cart GET /cart(.:format) cart#show
\n
"
,
Dir
.
chdir
(
app_path
){
`rake routes`
}
end
def
test_rake_routes_shows_custom_assets
...
...
@@ -100,7 +100,91 @@ def test_rake_routes_shows_custom_assets
get '/custom/assets', :to => 'custom_assets#show'
end
RUBY
assert_match
'custom_assets GET /custom/assets(.:format)'
,
Dir
.
chdir
(
app_path
){
`rake routes`
}
assert_equal
"custom_assets GET /custom/assets(.:format) custom_assets#show
\n
"
,
Dir
.
chdir
(
app_path
){
`rake routes`
}
end
def
test_rake_routes_shows_resources_route
app_file
"config/routes.rb"
,
<<-
RUBY
AppTemplate::Application.routes.draw do
resources :articles
end
RUBY
expected
=
" articles GET /articles(.:format) articles#index
\n
"
<<
" POST /articles(.:format) articles#create
\n
"
<<
" new_article GET /articles/new(.:format) articles#new
\n
"
<<
"edit_article GET /articles/:id/edit(.:format) articles#edit
\n
"
<<
" article GET /articles/:id(.:format) articles#show
\n
"
<<
" PUT /articles/:id(.:format) articles#update
\n
"
<<
" DELETE /articles/:id(.:format) articles#destroy
\n
"
assert_equal
expected
,
Dir
.
chdir
(
app_path
){
`rake routes`
}
end
def
test_rake_routes_shows_root_route
app_file
"config/routes.rb"
,
<<-
RUBY
AppTemplate::Application.routes.draw do
root :to => 'pages#main'
end
RUBY
assert_equal
"root / pages#main
\n
"
,
Dir
.
chdir
(
app_path
){
`rake routes`
}
end
def
test_rake_routes_shows_controller_and_action_only_route
app_file
"config/routes.rb"
,
<<-
RUBY
AppTemplate::Application.routes.draw do
match ':controller/:action'
end
RUBY
assert_equal
" /:controller/:action(.:format)
\n
"
,
Dir
.
chdir
(
app_path
){
`rake routes`
}
end
def
test_rake_routes_shows_controller_and_action_route_with_constraints
app_file
"config/routes.rb"
,
<<-
RUBY
AppTemplate::Application.routes.draw do
match ':controller(/:action(/:id))', :id => /
\\
d+/
end
RUBY
assert_equal
" /:controller(/:action(/:id))(.:format) {:id=>/
\\
d+/}
\n
"
,
Dir
.
chdir
(
app_path
){
`rake routes`
}
end
def
test_rake_routes_shows_route_with_defaults
app_file
"config/routes.rb"
,
<<-
RUBY
AppTemplate::Application.routes.draw do
match 'photos/:id' => 'photos#show', :defaults => {:format => 'jpg'}
end
RUBY
assert_equal
%Q[ /photos/:id(.:format) photos#show {:format=>"jpg"}
\n
]
,
Dir
.
chdir
(
app_path
){
`rake routes`
}
end
def
test_rake_routes_shows_route_with_constraints
app_file
"config/routes.rb"
,
<<-
RUBY
AppTemplate::Application.routes.draw do
match 'photos/:id' => 'photos#show', :id => /[A-Z]
\\
d{5}/
end
RUBY
assert_equal
" /photos/:id(.:format) photos#show {:id=>/[A-Z]
\\
d{5}/}
\n
"
,
Dir
.
chdir
(
app_path
){
`rake routes`
}
end
def
test_rake_routes_shows_route_with_rack_app
app_file
"lib/rack_app.rb"
,
<<-
RUBY
class RackApp
class << self
def call(env)
end
end
end
RUBY
app_file
"config/routes.rb"
,
<<-
RUBY
require 'rack_app'
AppTemplate::Application.routes.draw do
match 'foo/:id' => RackApp, :id => /[A-Z]
\\
d{5}/
end
RUBY
assert_equal
" /foo/:id(.:format) RackApp {:id=>/[A-Z]
\\
d{5}/}
\n
"
,
Dir
.
chdir
(
app_path
){
`rake routes`
}
end
def
test_logger_is_flushed_when_exiting_production_rake_tasks
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录