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

时间:2012-05-12 20:09:18

标签: ruby-on-rails routes

我有一个巨大的路由数量,我想增加几个数量级的路由器。有没有办法在路径文件的顶部添加'require'语句,并有一些其他文件包含其他路由?我不希望routes.rb文件长达一英里。

由于

2 个答案:

答案 0 :(得分:5)

你可以采取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

答案 1 :(得分:0)

试试这个  添加config / application.rb:

config.paths["config/routes"] << Rails.root.join('config/routes/you_route_file.rb')