Skip to content

Instantly share code, notes, and snippets.

@Flamefork
Created February 17, 2009 20:11
Show Gist options
  • Save Flamefork/65940 to your computer and use it in GitHub Desktop.
Save Flamefork/65940 to your computer and use it in GitHub Desktop.
# Fix routing to enable this:
#
# map.resources :organizations, :as => :root
#
# to produce this:
#
# organizations GET /
# new_organization GET /new
# edit_organization GET /:id/edit
# organization GET /:id
#
module ResourceAsRoot
module ResourcesHacks
def map_resource_routes map, resource, action, route_path, *args
route_path.gsub!(/\/\//, '/')
super
end
def map_resource entities, options = {}, *args
options[:as] = '' if options[:as] == :root
super
end
end
end
ActionController::Resources.send :include, ResourceAsRoot::ResourcesHacks
ActionController::Routing::RouteSet::Mapper.send :include, ResourceAsRoot::ResourcesHacks # Just cause it's too late
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment