Sha256: 46618c482d2c14eeb0d961768e47463e8aecb106406d2b2176616cf8eb269784

Contents?: true

Size: 1.48 KB

Versions: 2

Compression:

Stored size: 1.48 KB

Contents

#          Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
# All files in this distribution are subject to the terms of the Ruby license.

require 'ramaze'

# A very simple little application, you can simply run it and
# point your browser to http://localhost:7000
# you can change the port by setting
# Global.port = 80
# this most likely requires root-privileges though.

# This example shows following (requests to the mentioned base-url) :
# - simple text-output from the controller    [ / ]
# - showing you what your request looked like [ /simple ]
# - joining two strings                       [ /join/string1/string2 ]
# - join arbitary strings                     [ /join_all/string1/string2/string3 ... ]
# - sum two numbers                           [ /sum/1/3 ]
# - show if you made a POST or GET request    [ /post_or_get ]
# - How to map your controllers to urls       [ /other ]
# - Also try out the error-page, just pass something odd ;)


include Ramaze

class SimpleController < Controller
  def index
    "simple"
  end

  def simple
    request.inspect
  end

  def join first, second
    [first, second].join
  end

  def join_all *strings
    strings.join
  end
  
  def sum first, second
    first.to_i + second.to_i
  end
  
  def post_or_get
    request.post? ? 'POST' : 'GET'
  end
end

class OtherController < Controller
  def index
    "Hello, World from #{self.class.name}"
  end
end

Global.mapping = {
  '/'      => SimpleController,
  '/other' => OtherController
}

start

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ramaze-0.0.8 examples/simple.rb
ramaze-0.0.9 examples/simple.rb