This post originated from an RSS feed registered with Ruby Buzz
by Red Handed.
Original Post: One Small Serving of WebApp Tips
Feed Title: RedHanded
Feed URL: http://redhanded.hobix.com/index.xml
Feed Description: sneaking Ruby through the system
Maybe you remember Tanaka-san’s WebApp from a few weeks back. I’ve been using it here on the site to power our posting CGIs. It acts as a very simple wrapper for Hobix, which does the work of refreshing this site’s static HTML efficiently.
Time for a few undocumented tips I’ve picked up while sifting through the source.
Set ENV['WEBAPP_DEVELOP_HOST'] to your IP before you require 'webapp'. When exceptions are thrown, you’ll see the exception. Other users will get an error page.
Customize the debug and error pages by overriding WebApp::Manager#generate_debug_page and WebApp::Manager#generate_error_page.
WebApp works best when paths are addressed after the CGI’s path. Here’s a set of rewrite rules:
RewriteEngine On
RewriteCond %{REQUEST_URI} !webapp.cgi
RewriteRule ^(.*)$ /posts/webapp.cgi/$1
If using the above, you can generate links relative to the CGI path by using web.reluri( :path_info => '/posts/list' ).
You might want to alias the verbose accessors for GET and POST variables.
class WebApp
alias _get query_html_get_application_x_www_form_urlencoded
alias _post query_html_post_application_x_www_form_urlencoded
end