Partitioning routes file via draw?

35 views
Skip to first unread message

Kristian Mandrup

unread,
May 10, 2012, 3:24:20 AM5/10/12
to focused_c...@googlegroups.com
I think there used to be a draw helper that allowed you to partition the routes file into smalle parts, such as an admin routes, auth routes, social-api routes etc. I was really looking forward to using this feature. Any reason it was dropped?

Jon Leighton

unread,
May 10, 2012, 4:21:44 AM5/10/12
to focused_c...@googlegroups.com
That feature got added to Rails master but it hasn't been in any
released version yet.
--
http://jonathanleighton.com/

Chris Zwickilton

unread,
May 10, 2012, 9:00:07 AM5/10/12
to focused_c...@googlegroups.com
I just implemented this last night in my Rails 3.1 project.  All you have to do is add the following line to your application.rb:

config.paths['config/routes'].concat Dir[Rails.root.join("config/routes/*.rb")]

Then you can split up your routes however want by adding any arbitrary number of routes files to a new directory config/routes, ensuring that each one conforms to the original signature of:

your_application::Application.routes.draw do

end

This should also work with focused_controller since you are still routing within the normal routes draw block.

Kristian Mandrup

unread,
May 10, 2012, 9:23:20 AM5/10/12
to focused_c...@googlegroups.com
Would be nice with a convenient sort of helper in order to configure this. Either via an initalizer or directly in the application.rb

config.add_route_paths Dir[Rails.root.join("config/routes/*.rb")]

or simply 

config.add_route_path 'config/routes'

Just an idea.

Jon Leighton

unread,
May 10, 2012, 9:35:37 AM5/10/12
to focused_c...@googlegroups.com
This is really not a discussion for focused controller...
Reply all
Reply to author
Forward
0 new messages