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?
module ActionController
module Routing
class RouteSet
def add_routes
yield Mapper.new(self)
install_helpers([ActionController::Base, ActionView::Base], true)
end
end
end
end
ActionController::Routing::Routes.draw do |map| map.resources :foo end
ActionController::Routing::Routes.add_routes do |map| map.resources :bar end
ActionController::Routing::Routes.add_routes do |map| map.resources :baz 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.