Sha256: 57573908978bda4eba8cf112ce10a4b7871e773c3b30b91dbf02ecd069a43b33
Contents?: true
Size: 1.82 KB
Versions: 10
Compression:
Stored size: 1.82 KB
Contents
module RestAssured module RedirectRoutes def self.included(router) router.get '/redirects' do @redirects = Redirect.ordered haml :'redirects/index' end router.get '/redirects/new' do @redirect = Redirect.new haml :'redirects/new' end router.post '/redirects' do @redirect = Redirect.create(params['redirect'] || { :pattern => params['pattern'], :to => params['to'] }) if browser? if @redirect.errors.blank? flash[:notice] = "Redirect created" redirect '/redirects' else flash[:error] = "Crumps! " + @redirect.errors.full_messages.join("; ") haml :'redirects/new' end else if @redirect.errors.present? status 400 body @redirect.errors.full_messages.join("\n") end end end router.get %r{/redirects/(\d+)/edit} do |id| @redirect = Redirect.find(id) haml :'redirects/edit' end router.put %r{/redirects/(\d+)} do |id| @redirect = Redirect.find(id) @redirect.update_attributes(params['redirect']) if @redirect.save flash[:notice] = 'Redirect updated' redirect '/redirects' else flash[:error] = 'Crumps! ' + @redirect.errors.full_messages.join("\n") haml :'redirects/edit' end end router.put '/redirects/reorder' do if params['redirect'] if Redirect.update_order(params['redirect']) 'Changed' else 'Crumps! It broke' end end end router.delete %r{/redirects/(\d+)} do |id| if Redirect.destroy(id) flash[:notice] = 'Redirect deleted' redirect '/redirects' end end end end end
Version data entries
10 entries across 10 versions & 1 rubygems