将routes.rb 文件分成多个文件以便更好地管理的好方法是什么?
我正在开发一个 Rails 3 项目,该项目有一个相当大的路线文件。它利用了一些嵌套,我遇到了一个问题,主要是由于路由文件难以管理。
有没有办法把它分成多个文件?
比如:
My::Application.routes.draw do
constraints(:subdomain => 'admin') do
include My::Application::Routes::AdminRoutes
end
include My::Application::Routes::MainRoutes
end
或者……
My::Application.routes.draw do
constraints(:subdomain => 'admin') do
require 'routes/admin_routes.rb'
end
require 'routes/main_routes.rb'
end
或者类似的东西。
谢谢!
I am working on a rails 3 project with a fairly large routes file. It takes advantage of some nesting and I ran into an issue due largely to the fact that the routes files is difficult to manage.
Is there a way to break it up into multiple files?
Something like:
My::Application.routes.draw do
constraints(:subdomain => 'admin') do
include My::Application::Routes::AdminRoutes
end
include My::Application::Routes::MainRoutes
end
Or...
My::Application.routes.draw do
constraints(:subdomain => 'admin') do
require 'routes/admin_routes.rb'
end
require 'routes/main_routes.rb'
end
Or something along those lines.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
include
将包含的模块的方法插入到命名空间中,而require
只是将文件加载到顶级命名空间中。这些都不适合你。只需
加载
单独的文件include
inserts the included module's methods into the namespace, andrequire
just loads the file into the top level namespace. None of those will work for you.Just
load
the seperate files您可以使用的另一个选项
是将应用程序的根连接到默认控制器
another option you may use
this'll connect root of your application to default controller