First of all, Airbed performs a task similar to Rails’ RESTful routes. That is, requests made with HTTP verbs (GET, POST, PUT and DELETE) are mapped onto the CRUDdy actions: list, show, create, update, delete, plus those two also-rans new and edit (sort of).
The CRUDdy actions all have default implementations, using naming conventions to make it fly. To make overriding the defaults generally unnecessary, options can be passed, and various hooks are called during processing.
PUT and DELETE are not commonly supported by browsers: they’re faked in more or less the same way that Rails does, by adding a _verb parameter to requests.
a simple example
The doco is coming along as the behaviour’s being refined, but for now a simplified example is most eloquent. The full example is in airbed at examples/faces.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | Camping.goes :Faces
module Faces
module Models
class Person < Base; end
end
module Controllers
include Airbed::Resources
class Index < R '/'
def get
redirect People
end
end
class People < Resource Models::Person
def after_modification(instance)
redirect(People)
end
end
end
end |
View names are also inferred from naming conventions:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | module Faces
module Views
# TODO make this work by including Airbed::Views
def form(options={})
verb = method = options[:method] || :post
options[:method] = :post unless [:get,:post].include? method.to_sym
tag!(:form, options) {
input(:type => 'hidden', :name => '_verb', :value => verb)
yield
}
end
def _button(text,href,method=:post)
form(:action => href, :method => method) {
input :type => 'submit', :value => text
}
end
def list_people
h1 'ppl!'
ul {
@people.each {|person|
li { a person.name, :href => R(People,person) }
_button('x',R(People,person),:delete)
}
}
form( :action => R(People), :method => 'post') {
input :name => 'person[name]'
input :type => 'submit', :value => '+'
}
end
def show_person
h1 @person.name
form(:action => R(People,@person), :method => :put) {
input :name => 'person[name]', :value => @person.name
input :type => 'submit', :value => 'save'
}
a(:href => R(People)) {"← people"}
end
end
end |
gimme
Install with
1 | sudo gem install airbed |
or fetch head from
1 | svn co http://rails-oceania.rubyforge.org/svn/airbed/trunk/ |
The code is pretty new and shiny, so feedback in eminently welcome. Write some specs if you feel the inclination.

August 13, 2007 at 8:31 AM
Oooh noice. Can't wait to have a plays
December 19, 2007 at 11:53 PM
looking forward too that !
November 04, 2008 at 4:04 PM
Buy cheap viagra
impotence vacuum
10 pills x 100mg $39.95
30 pills x 100mg $89.95
60 pills x 100mg $129.95
90 pills x 100mg $149.95
November 13, 2008 at 3:50 AM
sp7pao5w7f8b0idv
November 13, 2008 at 8:13 AM
sp7pao5w7f8b0idv