# Gettin an input from user on html

**URL:** <https://www.ruby-forum.com/t/gettin-an-input-from-user-on-html/169877>\
**Category:** Ruby\
**Created:** [June 9, 2009, 9:53pm UTC](https://www.ruby-forum.com/t/gettin-an-input-from-user-on-html/169877 "2009-06-09T21:53:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![b1gtuna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8dc957/32.png) [@b1gtuna](https://www.ruby-forum.com/u/b1gtuna)\
**Post date:** [June 9, 2009, 9:53pm UTC](https://www.ruby-forum.com/t/gettin-an-input-from-user-on-html/169877/1 "2009-06-09T21:53:41Z")

</div>

Hello everyone, I am writing a small ruby script that lists all the  
files in a directory in a server at my work.

I wanna make buttons which users can click to sort the files.

Being a complete newbie, I don’t know how to approach this. I guess I  
can use the Mechanize gem, but looks overkill for this simple purpose.

Basically I need a simple way to invoke an array.sort method over http.

Thanks

---

<div class="post-metadata">

**Author:** ![b1gtuna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8dc957/32.png) [@b1gtuna](https://www.ruby-forum.com/u/b1gtuna)\
**Post date:** [June 10, 2009, 10:49am UTC](https://www.ruby-forum.com/t/gettin-an-input-from-user-on-html/169877/2 "2009-06-10T10:49:33Z")

</div>

Adam Lee wrote:

> Hello everyone, I am writing a small ruby script that lists all the  
> files in a directory in a server at my work.

Is this a script which is run from the command-line?

> I wanna make buttons which users can click to sort the files.

The question is, where do you want the button to appear?

If you want the button to appear on the user’s desktop or in a native UI  
window, then you need to use a UI library. There are many to choose  
from, but shoes is a good starting point: [http://www.shoooes.net/](http://www.shoooes.net/)

If you want the button to appear in the user’s web browser (e.g.  
Firefox, IE, Opera), then you need to write a web server which responds  
with the HTML to display a button. Look at Sinatra, Camping, Rails, or  
even CGI.

> Being a complete newbie, I don’t know how to approach this. I guess I  
> can use the Mechanize gem, but looks overkill for this simple purpose.
> 
> Basically I need a simple way to invoke an array.sort method over http.

It sounds like you may have got this all back-to-front.

There are two parties to HTTP: the client and the server. The client  
makes a request to the server, e.g. to fetch a page, and the server  
sends back the page. The client then does whatever it likes with the  
result, such as displaying it on-screen.

An example of a HTTP client is Firefox. And example of a HTTP server is  
Apache. You put the content in Apache, and you retrieve it using  
Firefox.

The Mechanize gem is also a HTTP client: you use it to connect to  
existing websites and fetch pages. Instead of rendering the results, it  
parses (breaks down) what it retrieves so you can process it in whatever  
way you like.

If you want to “make a button” as you say, in a user’s web browser, then  
you need the following to happen:

```
         HTTP GET /

```

client ------------------\> server  
\<------------------  
HTML response

The HTML response would contain the tags to display the button, e.g.

Then when the user clicks on the button, another exchange takes place:

```
         HTTP POST /sort

```

client ------------------\> server  
\<------------------  
HTML response

This HTML might contain a page with the filenames all nicely sorted.

I think that this is too general a question to take further here. I  
suggest you buy yourself a good book on Web programming, or google  
around for example Ruby code you can learn from.

There is detailled documentation on HTML at the [w3.org](http://w3.org) site - click on  
the ‘HTML’ link under ‘A to Z’, then ‘HTML 4.01 tutorial’. Also,  
detailed information is available under the ‘What - HTML 4.01’ link. For  
example, everything you could possibly want to know about HTML forms  
(including buttons) is at  
[Forms in HTML documents](http://www.w3.org/TR/html401/interact/forms.html)

There are tons of other HTML and web programming tutorials out there  
though. Google is your friend.

HTH,

Brian.

---

<div class="post-metadata">

**Author:** ![b1gtuna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8dc957/32.png) [@b1gtuna](https://www.ruby-forum.com/u/b1gtuna)\
**Post date:** [June 10, 2009, 3:03pm UTC](https://www.ruby-forum.com/t/gettin-an-input-from-user-on-html/169877/3 "2009-06-10T15:03:13Z")

</div>

That cleared up many things. Thanks a lot Brian!!!

---

<div class="post-metadata">

**Author:** ![b1gtuna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8dc957/32.png) [@b1gtuna](https://www.ruby-forum.com/u/b1gtuna)\
**Post date:** [June 10, 2009, 3:34pm UTC](https://www.ruby-forum.com/t/gettin-an-input-from-user-on-html/169877/4 "2009-06-10T15:34:08Z")

</div>

Ok my case is the last case: button appears on web browser.

Here is what has to happen: When user visits the page, he sees a list of  
items that was generated by Ruby script. Now there is a Sort button and  
when he clicks it it he now sees a list of sorted items.

The frameworks you have suggested like Rails seem to be too much for  
this simple function.

I guess right now (after studying bit about the HTTP GET/POST you  
mentioned) all I need to find out is how to trigger (invoke array.sort  
call) a ruby script passing.

Thank for your help Brian.
