require ‘rack’
require ‘json’
class MyApp
def call(env)
#puts JSON.pretty_generate(env)
@req = Rack::Request.new(env)
case @req.path
when ‘/’
body = <<-HTML
Username:
HTML
return [200, {‘Content-Type’ => ‘text/html’}, [body]]
when “/post_test”
if @req.post?
return [200, {‘Content-Type’ => ‘text/plain’},
[“you sent this POST data:n”,JSON.pretty_generate(@req.POST)]]
end
end
[404, {}, [“not found oO”]]
end
end
app = Rack::Builder.new{
use Rack::ShowExceptions
use Rack::Lint
use Rack::ContentLength
run MyApp.new
}.to_app
Rack::Handler::WEBrick.run(app, :Port => 4000)
What i’m trying to seperate the html form from inside ruby code.
Put the .html file in /var/www and put the .rb file seperate. Click the
form and it will execute the ruby code like:
Is it possible with apache webserver. Use fusion passenger if necessary.
Don’t re-write with CGI or something like cgi, rather try with rack.
Thanks.