Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
class TestController < ApplicationController def index @methods = %w{GET POST HEAD PUT DELETE PROPFIND PROPPATCH MKCOL COPY MOVE LOCK UNLOCK VERSION-CONTROL REPORT CHECKOUT CHECKIN UNCHECKOUT MKWORKSPACE UPDATE LABEL MERGE BASELINE-CONTROL MKACTIVITY ORDERPATCH ACL} end def echo m = request.head? ? 'HEAD' : request.method.to_s.upcase msg = m == params[:m].upcase ? 'OK' : "fail (got #{m})" response.headers['X-Test-success'] = msg expires_now render :text => msg end end ## views/test/index.rhtml [html] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Supported HTTP methods</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <%= javascript_include_tag 'prototype' %> <style type="text/css"> body { font:medium Verdana, sans-serif; padding:2em } #ua { font-size: 1.1em; color: firebrick; margin:1em 0; padding:0.3em 0.6em; background:#eee } #results .ok { color:green } #results .fail { color:goldenrod } #results .error { color:red } </style> </head> <body> <h1>Test what HTTP methods your browser supports</h1> <p>Tests are made by making an XMLHttpRequest for each of the methods and counting the ones succeded.</p> <h2 id="ua">[your user agent string]</h2> <div id="status"><img src="http://www.napyfab.com/ajax-indicators/images/progressbar_long_green.gif" alt="" /></div> <ol id="results"></ol> <script type="text/javascript"> $('ua').update(navigator.userAgent); function result(method, status){ var li = $(document.createElement('li')) li.update(method + ': ' + status) li.className = status.match(/^\w+/)[0].toLowerCase() $('results').appendChild(li) } var xhr, res, i=0, method, methods = [<%= @methods.map {|m| "'#{m}'"}.join(', ') %>] setTimeout(function(){ method = methods[i++] if(!method){ $('status').update('done.') return } xhr = Ajax.getTransport() res = 'undefined' try { xhr.open(method, 'echo?m='+method, false) xhr.send(null) res = xhr.getResponseHeader('X-Test-success') || xhr.responseText } catch (e) { res = 'error ('+e.toString()+')' } finally { result(method, res) } // throw $break setTimeout(arguments.callee, 10) }, 10) </script> </body> </html>
This paste will be private.
From the Design Piracy series on my blog: