简体   繁体   English

从几个文件中获取路由信息?

[英]get routing information from several files?

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? 有什么方法可以在路由文件的顶部添加“ require”语句,并使其他文件包含其他路由吗? I don't want the routes.rb file to be a mile long. 我不希望route.rb文件长一英里。

Thanks 谢谢

you can take DHHs approach to this: 您可以采用DHH方法:

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')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM