# HTML posting to ruby script?

**URL:** <https://www.ruby-forum.com/t/html-posting-to-ruby-script/174223>\
**Category:** Ruby\
**Created:** [August 22, 2009, 10:07pm UTC](https://www.ruby-forum.com/t/html-posting-to-ruby-script/174223 "2009-08-22T22:07:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![oshybrid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c68b51/32.png) [@oshybrid](https://www.ruby-forum.com/u/oshybrid)\
**Post date:** [August 22, 2009, 10:07pm UTC](https://www.ruby-forum.com/t/html-posting-to-ruby-script/174223/1 "2009-08-22T22:07:26Z")

</div>

Ok new to Ruby.

I have an HTML form that I want a user to enter data, and when the  
SUBMIT button is pressed, the HTML POST (with the data) goes to a Ruby  
script to process the data (no web server running) into ruby variables  
to be used in other Ruby Scripts.

Again this is meant to be able to run offline because ultimately this is  
all going into the “Titanium” app runtime (Similar to adobe AIR, but  
Ruby and Python runtimes are included), and like AIR can run on any  
platform.

In short it becomes a multi-platform desktop app using HTML as the GUI.

Question is, how do I get that ruby script to accept the POST and pull  
the data out to make the variables?

---

<div class="post-metadata">

**Author:** ![oshybrid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c68b51/32.png) [@oshybrid](https://www.ruby-forum.com/u/oshybrid)\
**Post date:** [August 23, 2009, 1:05am UTC](https://www.ruby-forum.com/t/html-posting-to-ruby-script/174223/2 "2009-08-23T01:05:43Z")

</div>

Den Sat, 22 Aug 2009 15:07:33 -0500 skrev Brad Mr:

> platform.
> 
> In short it becomes a multi-platform desktop app using HTML as the GUI.
> 
> Question is, how do I get that ruby script to accept the POST and pull  
> the data out to make the variables?

You need a webserver. Can be a simple one, can even be written in  
Ruby, but you do need one.

/Kent

---

<div class="post-metadata">

**Author:** ![oshybrid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c68b51/32.png) [@oshybrid](https://www.ruby-forum.com/u/oshybrid)\
**Post date:** [August 23, 2009, 6:57am UTC](https://www.ruby-forum.com/t/html-posting-to-ruby-script/174223/3 "2009-08-23T06:57:38Z")

</div>

Brad Mr wrote:

> Ok new to Ruby.
> 
> I have an HTML form that I want a user to enter data, and when the  
> SUBMIT button is pressed, the HTML POST (with the data) goes to a Ruby  
> script to process the data (no web server running) into ruby variables  
> to be used in other Ruby Scripts.
> 
> Again this is meant to be able to run offline

Web pages have no access to the local file system–for security reasons.  
You wouldn’t be able to browser the internet if a web page could  
suddenly flood every folder on your computer with thousands of  
advertisements. And you say that the web browser is offline, which  
means the web page can’t communicate with a server. So the question is:  
where is the ruby script located? You see the dilemma?

---

<div class="post-metadata">

**Author:** ![oshybrid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c68b51/32.png) [@oshybrid](https://www.ruby-forum.com/u/oshybrid)\
**Post date:** [August 24, 2009, 4:17pm UTC](https://www.ruby-forum.com/t/html-posting-to-ruby-script/174223/4 "2009-08-24T16:17:53Z")

</div>

7stud – wrote:

> Brad Mr wrote:
> 
> > Ok new to Ruby.
> > 
> > I have an HTML form that I want a user to enter data, and when the  
> > SUBMIT button is pressed, the HTML POST (with the data) goes to a Ruby  
> > script to process the data (no web server running) into ruby variables  
> > to be used in other Ruby Scripts.
> > 
> > Again this is meant to be able to run offline
> 
> Web pages have no access to the local file system–for security reasons.  
> You wouldn’t be able to browser the internet if a web page could  
> suddenly flood every folder on your computer with thousands of  
> advertisements. And you say that the web browser is offline, which  
> means the web page can’t communicate with a server. So the question is:  
> where is the ruby script located? You see the dilemma?

If that is true then how does Javascript work if you make all function  
definition in a single seperate \*.js file while, calls to its function,  
and you don’t need a web server for that?

---

<div class="post-metadata">

**Author:** ![oshybrid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c68b51/32.png) [@oshybrid](https://www.ruby-forum.com/u/oshybrid)\
**Post date:** [August 31, 2009, 10:19pm UTC](https://www.ruby-forum.com/t/html-posting-to-ruby-script/174223/5 "2009-08-31T22:19:19Z")

</div>

Den Mon, 24 Aug 2009 09:17:56 -0500 skrev Brad Mr:

> > Web pages have no access to the local file system–for security reasons.  
> > You wouldn’t be able to browser the internet if a web page could  
> > suddenly flood every folder on your computer with thousands of  
> > advertisements. And you say that the web browser is offline, which  
> > means the web page can’t communicate with a server. So the question is:  
> > where is the ruby script located? You see the dilemma?
> 
> If that is true then how does Javascript work if you make all function  
> definition in a single seperate \*.js file while, calls to its function,  
> and you don’t need a web server for that?

Javascript runs in the browser.

/Kent

---

<div class="post-metadata">

**Author:** ![oshybrid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c68b51/32.png) [@oshybrid](https://www.ruby-forum.com/u/oshybrid)\
**Post date:** [August 23, 2009, 9:25am UTC](https://www.ruby-forum.com/t/html-posting-to-ruby-script/174223/6 "2009-08-23T09:25:28Z")

</div>

Brad Mr wrote:

> In short it becomes a multi-platform desktop app using HTML as the GUI.

You need a small webserver, which can be bound to 127.0.0.1 (so that  
browsers on remote machines cannot access it). You would then point your  
browser at [http://127.0.0.1](http://127.0.0.1):xxxx/ where xxxx is whatever port you bound  
the webserver to.

Sinatra looks to be a very good match to your requirements.

require ‘rubygems’  
require ‘sinatra’  
post ‘/submit’ do  
… do stuff using posted params[]  
… return a string containing the response page  
end

---

<div class="post-metadata">

**Author:** ![oshybrid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c68b51/32.png) [@oshybrid](https://www.ruby-forum.com/u/oshybrid)\
**Post date:** [September 1, 2009, 9:53am UTC](https://www.ruby-forum.com/t/html-posting-to-ruby-script/174223/7 "2009-09-01T09:53:32Z")

</div>

Brad Mr wrote:

> (no web server running)

A program that handles http messages is called a web server so you have  
to have one. The simplest solution is to use the normal Ruby web server  
options, running locally as mentioned in another post. Why did you  
decide you wanted to avoid this approach?
