Module: Waves::Mapping::PrettyUrls::RestRules
- Defined in:
- lib/mapping/pretty_urls.rb
Overview
RestRules defines the following URL conventions:
POST /resources # => add a new resource
PUT /resource/name # => update the given resource
DELETE /resource/name # => delete the given resource
Class Method Summary collapse
Class Method Details
.included(target) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/mapping/pretty_urls.rb', line 58 def self.included(target) target.module_eval do extend Waves::Mapping name = '([\w\-\_\.\+\@]+)'; model = '([\w\-]+)' # create a new resource for the given model path %r{^/#{model}/?$}, :method => :post do | model | resource( model.singular ) do instance = controller { create } redirect( "/#{model.singular}/#{instance.name}/editor" ) end end # update the given resource for the given model path %r{^/#{model}/#{name}/?$}, :method => :put do | model, name | resource( model ) { controller { update( name ) }; redirect( url ) } end # delete the given resource for the given model path %r{^/#{model}/#{name}/?$}, :method => :delete do | model, name | resource( model ) { controller { delete( name ) } } end end end |