Skip to content

Instantly share code, notes, and snippets.

@ahawkins
Created January 6, 2011 11:52
Show Gist options
  • Save ahawkins/767804 to your computer and use it in GitHub Desktop.
Save ahawkins/767804 to your computer and use it in GitHub Desktop.
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