在rails 4中重构一个大的routes.rb文件

我正在将rails 3应用程序升级到rails 4.0.1。

在我的rails 3应用程序中,我在application.rb中使用以下代码来使用多个路由文件。

config.paths [“config / routes”] + = Dir [Rails.root.join(’config’,’routes’,’* .rb’)。to_s]

但是当我尝试在rails 4中使用相同的东西时抛出exception。

有小费吗?

在我的一个较大的应用程序中,我在config / routes.rb文件中使用以下代码段。

 class ActionDispatch::Routing::Mapper def draw(routes_name) instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb"))) end end YourApplication::Application.routes.draw do # Loads config/routes/common.rb draw :common # Loads config/routes/another.rb draw :another end 

Rails 4最初支持draw :routeName但它已被删除,因为它没有显示任何改进。 (我不知道^。^)你可以在这里查看git提交: https : //github.com/rails/rails/commit/5e7d6bba79393de0279917f93b82f3b7b176f4b5

看看这个SO答案: rails 4:将routes.rb拆分成多个较小的文件

看起来这种能力在Rails 4中已被弃用。

我不知道你的申请有多大。 但是如果你需要使用Rails路由进行适当的重构,你应该研究rails 4中的路由问题 。

莫’档,莫’问题。