[英]get routing information from several files?
我有大量的路线,而且我想增加几个数量级。 有什么方法可以在路由文件的顶部添加“ require”语句,并使其他文件包含其他路由吗? 我不希望route.rb文件长一英里。
谢谢
您可以采用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.