How to receive return from HTML textbox using ruby? -
i creating chat client/server system in ruby.
my server hosted on laptop or (this class project, not processing power needed) , plan client take place in web browser.
i feed html 2 textboxes: 1 in user can type , other display chat history.
my problem while can feed html code browser , display chat (navigate ip address:port) can't figure out how can return input in textbox server.
does know how this?
it sounds need basic knowledge of how cgis work. once know find easier work sinatra, @echoback recommended, or padrino, rails, or work other languages.
this pretty basic cgi. generates simple form, along lines of talking about, walks through environment table passed ruby web server, sorts keys, , outputs table in sorted order. of fields directly apply either web server itself, or cgi, such query sent browser, along headers sent server saying capabilities are:
#!/usr/bin/env ruby puts "content-type: text/html" puts puts "<html><head><style type='text/css'>body{font-family: monospace;}</style></head><body>" puts "<form name='foo' action='test_cgi.rb'>" puts "<input type='textinput' name='inputbox'></input><br />" puts "<textarea name='textareabox'></textarea><br />" puts "<input type='submit'></input>" puts "</form>" puts "<h4>environment:</h4>" puts "<table>" env.keys.sort.each |k| puts "<tr><td>#{k}</td><td>#{env[k]}</td></tr>" end puts "</table>" puts "</body></html>"
copy code, store ruby file called test_cgi.rb
, set executable bit on file. move file cgi-bin
directory of web server on machine. use browser access file (http://localhost:8080/cgi-bin/test_cgi.rb
or similar), , watch output in table change enter different values in form , submit them.
once understand round-trip server browser server you'll in place learn how sinatra builds on rack supply more features, more easily, doing cgi.
Comments
Post a Comment