[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Gettin an input from user on html

Adam Lee

6/9/2009 7:54:00 PM

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-....

6 Answers

Brian Candler

6/10/2009 8:50:00 AM

0

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.sh...

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/...

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

HTH,

Brian.
--
Posted via http://www.ruby-....

Adam Lee

6/10/2009 1:04:00 PM

0

That cleared up many things. Thanks a lot Brian!!!
--
Posted via http://www.ruby-....

Adam Lee

6/10/2009 1:34:00 PM

0

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-....

Jeff

10/18/2011 9:14:00 PM

0

On Oct 18, 1:34 pm, Donna <tom.r...@ix.netcom.com> wrote:
> On Oct 18, 2:23 pm, Donna <tom.r...@ix.netcom.com> wrote:
>
>
>
>
>
>
>
>
>
> > On Oct 18, 1:45 pm, "who?" <yourimageunre...@sbcglobal.net> wrote:
>
> > > I said what I said about Paul once that I know of. You're
> > > moving the goal post because I haven't repeated myself
> > > a million times like you all bash Yoko.
>
> > Jeff, your exact words were, "That saying doesn't apply to Yoko and
> > there is nothing to be gained by attacking her. She didn't commit a
> > crime."
>
> > I know I missed a zillion Yoko posts, but from that statement, alone,
> > it doesn't appear that you're saying that people "shouldn't criticize
> > Yoko."  You're merely saying that there's nothing to be gained by it.
> > In fact, I don't recall anyone ever stating or even implying such a
> > thing, but that's not to say that no one ever did.  Help me out here.
> > Has anyone stated that she should not be criticized?
>
> I should just add one more thing, Jeff.  If you're saying that the
> constant repetition bothers you, then why did you start this thread?
> Didn't you know how it would play out?

How it played out is I have an appointment to have a CD player
installed in my car right now.

Jeff

10/18/2011 11:14:00 PM

0

On Oct 18, 1:34 pm, Donna <tom.r...@ix.netcom.com> wrote:
> On Oct 18, 2:23 pm, Donna <tom.r...@ix.netcom.com> wrote:
>
>
>
>
>
>
>
>
>
> > On Oct 18, 1:45 pm, "who?" <yourimageunre...@sbcglobal.net> wrote:
>
> > > I said what I said about Paul once that I know of. You're
> > > moving the goal post because I haven't repeated myself
> > > a million times like you all bash Yoko.
>
> > Jeff, your exact words were, "That saying doesn't apply to Yoko and
> > there is nothing to be gained by attacking her. She didn't commit a
> > crime."
>
> > I know I missed a zillion Yoko posts, but from that statement, alone,
> > it doesn't appear that you're saying that people "shouldn't criticize
> > Yoko."  You're merely saying that there's nothing to be gained by it.
> > In fact, I don't recall anyone ever stating or even implying such a
> > thing, but that's not to say that no one ever did.  Help me out here.
> > Has anyone stated that she should not be criticized?
>
> I should just add one more thing, Jeff.  If you're saying that the
> constant repetition bothers you, then why did you start this thread?
> Didn't you know how it would play out?

Smile, Donna. I'm asking you the same thing about questioning
Fatt? Smile some more.

1. I really wrote this thread for Danny clowning around.

2. I meant no harm to Fatt and should have said nothing.
Her and I are friends just like you and I, and UpserTom
are.

3. Tom brings Paul into it. I don't know why.

4. I was bored and started this thread just like people
go out and play ping pong or tennis.

:-)

Jeff

10/18/2011 11:23:00 PM

0

On Oct 18, 10:23 am, Billy <billybartlet...@yahoo.com> wrote:
> On Oct 17, 10:31 pm, marcus <marcus...@yahoo.com> wrote:
>
> > On Oct 17, 12:55 pm, Donna <tom.r...@ix.netcom.com> wrote:
> > After years of talking about her here,
>
> > > not much has changed in the way of swaying a lot of posters over to
> > > your point of view.  So why go on?  And why would the opinion of
> > > others even matter so much to you?  What are you looking for them to
> > > do with the information that you present?  Really, I'm just curious,
>
> > Those who go on and on about Yoko want one thing...to have other
> > people agree with them, and tell them how right they are.
>
> > And that is your answer, Donna.
>
> You don't think it's EVER anything more than that?   You don't think
> Yoko's critics ever want a debate?  

What's there to debate besides ganging up on a woman
who is almost 80 years old, for how things went down
with a rock band that ended 40 years ago? It might
have made sense 30 years ago when they might have
reunited, but 2 of them are now dead.