将路由文件拆分为多个文件 [英] Splitting Routes File Into Multiple Files
本文介绍了将路由文件拆分为多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Rails 3应用程序,并且我想根据子域将路由分成单独的文件。现在,我的routes.rb文件中包含以下内容:
I'm working w/ a Rails 3 application and I want to split up the routes into separate files depending on the subdomain. Right now I have this in my routes.rb file:
Skateparks::Application.routes.draw do
constraints(:subdomain => 'api') do
load 'routes/api.rb'
end
end
在我的路线/api.rb文件中,我有:
And In my routes/api.rb file I have:
resources :skateparks
这似乎不起作用,因为如果我运行 rake路线我得到
This doesn't seem to work though because if I run rake routes
I get
undefined method `resources' for main:Object
此外,如果我尝试导航到 http://0.0.0.0:3000/ 我得到:
Also, if I try to navigate to http://0.0.0.0:3000/ I get:
路由错误
Routing Error
No route matches "/"
推荐答案
在Rails 3.2中,config.paths现在是一个哈希,因此@sunkencity的解决方案可以修改为:
In Rails 3.2, config.paths is now a hash, so @sunkencity's solution can be modified to:
# config/application.rb
config.paths["config/routes"] << File.join(Rails.root, "config/routes/fooroutes.rb")
这篇关于将路由文件拆分为多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文