I have a huge number of routes, and I'd like to add in orders of magnitude more. Is there any way to add a 'require' statement at the top of the routes file, and have some other file(s) house the additional routes? I don't want the routes.rb file to be a mile long.
Thanks
you can take DHHs approach to this:
class ActionDispatch::Routing::Mapper
def draw(routes_name)
instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb")))
end
end
BCX::Application.routes.draw do
draw :api
draw :account
draw :session
draw :people_and_groups
draw :projects
draw :calendars
draw :legacy_slugs
draw :ensembles_and_buckets
draw :globals
draw :monitoring
draw :mail_attachments
draw :message_preview
draw :misc
root to: 'projects#index'
end
尝试在config / application.rb中添加:
config.paths["config/routes"] << Rails.root.join('config/routes/you_route_file.rb')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.