instance method
draw
Ruby on Rails 7.2.3
Since v6.1.7.10Signature
draw(name)
Loads another routes file with the given name located inside the config/routes directory. In that file, you can use the normal routing DSL, but do not surround it with a Rails.application.routes.draw block.
# config/routes.rb Rails.application.routes.draw do draw :admin # Loads `config/routes/admin.rb` draw "third_party/some_gem" # Loads `config/routes/third_party/some_gem.rb` end # config/routes/admin.rb namespace :admin do resources :accounts end # config/routes/third_party/some_gem.rb mount SomeGem::Engine, at: "/some_gem"
CAUTION: Use this feature with care. Having multiple routes files can negatively impact discoverability and readability. For most applications —even those with a few hundred routes — it’s easier for developers to have a single routes file.
Parameters
-
namereq
Source
# File actionpack/lib/action_dispatch/routing/mapper.rb, line 1657
def draw(name)
path = @draw_paths.find do |_path|
File.exist? "#{_path}/#{name}.rb"
end
unless path
msg = "Your router tried to #draw the external file #{name}.rb,\n" \
"but the file was not found in:\n\n"
msg += @draw_paths.map { |_path| " * #{_path}" }.join("\n")
raise ArgumentError, msg
end
route_path = "#{path}/#{name}.rb"
instance_eval(File.read(route_path), route_path.to_s)
end
Defined in actionpack/lib/action_dispatch/routing/mapper.rb line 1657
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActionDispatch::Routing::Mapper::Resources