From: gmspro gmspro Date: 2012-10-30T13:15:04+09:00 Subject: 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) # run ruby # and visit http://127.0.0.1:4000/ in your browser. # Content-Encoding 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. -- Posted via http://www.ruby-forum.com/.