Sha256: ea7ebb25897a34b6d5648dcad5894081075a929e96a2517b8a2b72e3b2b49192

Contents?: true

Size: 1.88 KB

Versions: 3

Compression:

Stored size: 1.88 KB

Contents

$:.unshift( "../lib" )
require 'capcode'
require 'rubygems'

module Capcode
  class Index < Route '/'
    def get
      render :markaby => :index, :layout => :forms
    end
  end
  
  class Action < Route "/action"
    def any
      @method = env["REQUEST_METHOD"]
      log.write( "#{@method}...\n" )
      @data = params["data"]
      render :markaby => :action, :layout => :forms
    end
   
    def delete
      log.write( "DELETE...\n" )
      @method = "DELETE"
      @data = params["data"]
      render :markaby => :action, :layout => :forms
    end
    
    def put
      log.write( "PUT...\n" )
      @method = "PUT"
      @data = params["data"]
      render :markaby => :action, :layout => :forms
    end
    
  end
end

module Capcode::Views
  def forms
    html do
      body do
        yield
        
        form :method => "GET", :action => URL(Capcode::Action) do
          input :type => "text", :name => "data";
          input :type => "submit", :value => "GET"
        end
        
        form :method => "POST", :action => URL(Capcode::Action) do
          input :type => "text", :name => "data";
          input :type => "submit", :value => "POST"
        end

        form :method => "POST", :action => URL(Capcode::Action) do
          input :type => "hidden", :name => "_method", :value => "delete" ## <-- You need this 
          input :type => "text", :name => "data";
          input :type => "submit", :value => "DELETE"
        end

        form :method => "POST", :action => URL(Capcode::Action) do
          input :type => "hidden", :name => "_method", :value => "put" ## <-- You need this 
          input :type => "text", :name => "data";
          input :type => "submit", :value => "PUT"
        end
      end
    end
  end
  
  def index
    h1 "Hello !"
  end
  
  def action
    text "You send "; b @data; text " using a "; b @method; text " method!"; br
  end
  
end

#Capcode.run( )

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
Capcode-1.0.0 examples/rest.rb
Capcode-0.9.9 examples/rest.rb
Capcode-0.9.8 examples/rest.rb