开发者

What is a good way to break your routes.rb file into multiple files for better management?

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 is开发者_JS百科sue 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!


include inserts the included module's methods into the namespace, and require just loads the file into the top level namespace. None of those will work for you.

Just load the seperate files

My::Application.routes.draw do
  constraints(:subdomain => 'admin') do
    load 'routes/admin_routes.rb'
  end

  load 'routes/main_routes.rb'
end


another option you may use

ActionController::Routing::Routes.draw do |map| #routes.rb

  extend NewConnections

  some_method(map)  

end 


module NewConnections #/lib/new_connections.rb

  def some_method(clazz)
    clazz.root :controller => "demo"
  end

end

this'll connect root of your application to default controller

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜