1 2 3
ActionController::Routing::Routes.draw do |map| eval(File.open(File.dirname(__FILE__) + '/../path/to/another/routes/file.rb', 'r').read) end
Refactorings
No refactoring yet !
Jesse Newland
March 7, 2008, March 07, 2008 23:29, permalink
Works on edge. Why are you doing this, though?
duck punch!
1 2 3 4 5 6 7 8 9 10
module ActionController module Routing class RouteSet def add_routes yield Mapper.new(self) install_helpers([ActionController::Base, ActionView::Base], true) end end end end
first routes file
1 2 3
ActionController::Routing::Routes.draw do |map| map.resources :foo end
second routes file
1 2 3
ActionController::Routing::Routes.add_routes do |map| map.resources :bar end
third routes file
1 2 3
ActionController::Routing::Routes.add_routes do |map| map.resources :baz end
leethal
April 7, 2008, April 07, 2008 10:58, permalink
Routes
1 2 3 4
ActionController::Routing::Routes.draw do |map| require '../lib/extra_routes.rb' ExtraRoutes.add(map) end
The module (lib/extra_routes.rb)
1 2 3 4 5 6 7 8
module ExtraRoutes def add(map) map.resources :foo map.burger :bar end module_function :add end
I'm trying to retain the rails routing DSL but maintain it in two files. This is the only way I've found so far to get it to work.
I can't use another ActionController::Routing::Routes.draw block because here is the draw code from Rails:
def draw
clear!
yield Mapper.new(self)
install_helpers
end
Simply loading the file doesn't retain variable scope.