Created
January 6, 2011 11:52
-
-
Save ahawkins/767804 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ScopeNamedRoutes | |
def self.included(klass) | |
klass.class_eval do | |
actual_routes = [] | |
Rails.application.routes.named_routes.routes.each {|name, r| actual_routes << r } | |
scoped_routes = actual_routes.select do |route| | |
Rails.logger.debug route.path | |
route.path.match(/^\/:account_id\//) | |
end | |
scoped_routes.each do |route_to_scope| | |
[:url, :path].each do |ext| | |
klass.class_eval <<-OVER_RIDE | |
def #{route_to_scope.name}_#{ext}(*args) | |
with_account = [Account.first] + args | |
super(*with_account) | |
end | |
OVER_RIDE | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment