本文介绍了如何将 routes.rb 拆分成更小的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以拆分 Rails 3.X routes.rb 文件?
Is it possible to split Rails 3.X routes.rb file?
我们的资源太多了,很难找到.我想至少拆分 APP 和 REST API 路由.
We have so many resources it is difficult to find them. I would like to split at least APP and REST API routes.
谢谢!
推荐答案
你可以这样做:
routes.rb
require 'application_routes'
require 'rest_api_routes'
lib/application_routes.rb
lib/application_routes.rb
YourApplication::Application.routes.draw do
# Application related routes
end
lib/rest_api_routes.rb
lib/rest_api_routes.rb
YourApplication::Application.routes.draw do
# REST API related routes
end
更新:(此方法已从 Rails 中删除)
Rails edge 刚刚增加了一个很好的附加功能,多个路由文件:
Rails edge just got a great addition, multiple route files:
# config/routes.rb
draw :admin
# config/routes/admin.rb
namespace :admin do
resources :posts
end
这对于分解大型应用中的复杂路由文件非常方便.
This will come handy for breaking down complex route files in large apps.
这篇关于如何将 routes.rb 拆分成更小的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!