The Camping Short, Short Example
Camping encourages short, elegant applications. In this example, we’re going to skip the database and put together a simple home page with a few of your favorite links.
The site can be stored in a single file called homepage.rb. Run it like: camping homepage.rb
#!ruby
#!/usr/local/bin/ruby -rubygems
require ‘camping’
Camping.goes :HomePage
module HomePage::Controllers
# The root slash shows the `index’ view.
class Index Views#index
# /sample -> Views#sample
#
class Page ‘http://google.com’ }
li { a ‘A sample page’, :href => ‘/sample’ }
end
end
# The `sample’ view.
def sample
p ‘A sample page’
end
end
This example doesn’t have any Models (the database objects.) Since those are just ActiveRecord objects, it’s probably best to learn about those from the ActiveRecord Base documentation.
Further Examples
Camping includes a number of other larger examples!
Blog: An expanded clone of http://k4ml.com/wiki/python/webpy/simpleblog, which includes sessioning examples.
Tepee: A fine little Wiki, versioning and Textile.
Campsh: A Wiki for storing scripts which can then be run from the browser.