Can you rewrite this ruby form post with rack?

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.

gmspro gmspro wrote in post #1081918:

What i’m trying to seperate the html form from inside ruby code.

Open the .html form, read it, interpolate it, assign the result to body.
(Using something like erb)
But it would be better to use Sinatra instead, as it has all the helpers
built-in to do this.

Don’t re-write with CGI or something like cgi, rather try with rack.

Sinatra apps are just Rack apps.