Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Is it possible to split Rails 3.X routes.rb file?

We have so many resources it is difficult to find them. I would like to split at least APP and REST API routes.

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
716 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can do that:

routes.rb

require 'application_routes'
require 'rest_api_routes'

lib/application_routes.rb

YourApplication::Application.routes.draw do
  # Application related routes
end

lib/rest_api_routes.rb

YourApplication::Application.routes.draw do
  # REST API related routes
end

UPDATE: (This method has since been removed from Rails)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...