Skip to content

Commit d654bba

Browse files
Merge pull request #46211 from hmbreaux/add-doc-routing-draw-method
Add API documentation for Routing#draw [ci-skip] (cherry picked from commit 348e609)
1 parent 665dc15 commit d654bba

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

actionpack/lib/action_dispatch/routing/mapper.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,6 +1584,29 @@ def shallow?
15841584
!parent_resource.singleton? && @scope[:shallow]
15851585
end
15861586

1587+
# Loads another routes file with the given +name+ located inside the
1588+
# +config/routes+ directory. In that file, you can use the normal
1589+
# routing DSL, but <i>do not</i> surround it with a
1590+
# +Rails.application.routes.draw+ block.
1591+
#
1592+
# # config/routes.rb
1593+
# Rails.application.routes.draw do
1594+
# draw :admin # Loads `config/routes/admin.rb`
1595+
# draw "third_party/some_gem" # Loads `config/routes/third_party/some_gem.rb`
1596+
# end
1597+
#
1598+
# # config/routes/admin.rb
1599+
# namespace :admin do
1600+
# resources :accounts
1601+
# end
1602+
#
1603+
# # config/routes/third_party/some_gem.rb
1604+
# mount SomeGem::Engine, at: "/some_gem"
1605+
#
1606+
# <b>CAUTION:</b> Use this feature with care. Having multiple routes
1607+
# files can negatively impact discoverability and readability. For most
1608+
# applications — even those with a few hundred routes — it's easier for
1609+
# developers to have a single routes file.
15871610
def draw(name)
15881611
path = @draw_paths.find do |_path|
15891612
File.exist? "#{_path}/#{name}.rb"

guides/source/routing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,7 @@ video = Video.find_by(identifier: "Roman-Holiday")
12731273
edit_video_path(video) # => "/videos/Roman-Holiday/edit"
12741274
```
12751275

1276-
Breaking Up *Very* Large Route File into Multiple Small Ones:
1276+
Breaking Up *Very* Large Route File into Multiple Small Ones
12771277
-------------------------------------------------------
12781278

12791279
If you work in a large application with thousands of routes, a single `config/routes.rb` file can become cumbersome and hard to read.

0 commit comments

Comments
 (0)