Sha256: 2ee7c426958ef51fef502382700c8b90b7c406ed0a1ed6f7aad4fb438bc430ac

Contents?: true

Size: 1.82 KB

Versions: 7

Compression:

Stored size: 1.82 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 get( )
      @method = env["REQUEST_METHOD"]
      @data = params["data"]
      render :markaby => :action, :layout => :forms
    end
   
    alias_method :post, :get
    
    def delete
      @method = "DELETE"
      @data = params["data"]
      render :markaby => :action, :layout => :forms
    end
    
    def put
      @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

7 entries across 7 versions & 1 rubygems

Version Path
Capcode-0.9.7 examples/rest.rb
Capcode-0.9.6 examples/rest.rb
Capcode-0.9.5 examples/rest.rb
Capcode-0.9.4 examples/rest.rb
Capcode-0.9.3 examples/rest.rb
Capcode-0.9.2 examples/rest.rb
Capcode-0.9.1 examples/rest.rb