Gettin an input from user on html

Discussion in 'Ruby' started by Adam Lee, Jun 9, 2009.

  1. Adam Lee

    Adam Lee Guest

    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
    --
    Posted via http://www.ruby-forum.com/.
     
    Adam Lee, Jun 9, 2009
    #1
    1. Advertising

  2. 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/.
     
    Brian Candler, Jun 10, 2009
    #2
    1. Advertising

  3. Adam Lee

    Adam Lee Guest

    Adam Lee, Jun 10, 2009
    #3
  4. Adam Lee

    Adam Lee Guest

    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.
    --
    Posted via http://www.ruby-forum.com/.
     
    Adam Lee, Jun 10, 2009
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. karthikeyavenkat
    Replies:
    2
    Views:
    630
    Bryce
    Mar 17, 2005
  2. kkrish
    Replies:
    5
    Views:
    344
    Oliver Wong
    Jul 18, 2006
  3. Elie Grouchko

    Gettin detailed error information from IIS

    Elie Grouchko, Dec 11, 2005, in forum: ASP General
    Replies:
    0
    Views:
    139
    Elie Grouchko
    Dec 11, 2005
  4. why the lucky stiff
    Replies:
    0
    Views:
    112
    why the lucky stiff
    Mar 29, 2005
  5. Michal Gabrukiewicz
    Replies:
    6
    Views:
    199
    Daniel Martin
    Dec 1, 2007
Loading...

Share This Page