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/

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.
  <form action="/sort">
    <input type="submit" value="sort"/>
  </form>

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 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 
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.
-- 
Posted via http://www.ruby-forum.com/.