Skip to content

Instantly share code, notes, and snippets.

@clr
Created April 1, 2011 21:44
Show Gist options
  • Save clr/898924 to your computer and use it in GitHub Desktop.
Save clr/898924 to your computer and use it in GitHub Desktop.
Stick this in your initializers dir for better routing.
module ActionDispatch
module Routing
class Mapper
module MapRestfully
def map_restfully(resource_name, options={})
singular = resource_name.to_s
plural = options[:plural] || singular.pluralize
%w(get post put delete).each do |verb|
match({"#{singular}(/:id(.:format))" => "#{plural}##{verb}", :via => verb, :as => singular}.merge(options))
match "#{plural}(/:ids(.:format))" => "#{plural}##{verb}s", :via => verb, :as => plural
end
end
end
include MapRestfully
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment