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)) {"&larr; 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.

  1. Tim Lucas says:

    Oooh noice. Can't wait to have a plays

  2. shawn wilson says:

    looking forward too that !

  3. DiatgreargO says:

    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

  4. Freddy Barry says:

    sp7pao5w7f8b0idv

  5. Saul Workman says:

    sp7pao5w7f8b0idv

Post a comment


( lesstile enabled - surround code blocks with ---)