Professional Web Applications Themes

Puzzling... - Ruby

Hi, I have these 2 files, one work and the other does not. #!c:/apps/ruby/bin/ruby.exe print "Content-type: text/html \n\n\n" print "1st line " print "2nd line " print "3rd line " And this is the other one(DOES NOT WORK!) #!c:/apps/ruby/bin/ruby.exe print "Content-type: text/plain \n\n\n" print "1st line " print "2nd line " print "3rd line " The only difference is that the 2nd file has text/plain in the header instead of text/html. Please advise. Thanks...

  1. #1

    Default Puzzling...

    Hi, I have these 2 files, one work and the other does not.

    #!c:/apps/ruby/bin/ruby.exe
    print "Content-type: text/html \n\n\n"
    print "1st line "
    print "2nd line "
    print "3rd line "

    And this is the other one(DOES NOT WORK!)
    #!c:/apps/ruby/bin/ruby.exe
    print "Content-type: text/plain \n\n\n"
    print "1st line "
    print "2nd line "
    print "3rd line "

    The only difference is that the 2nd file has text/plain in the header
    instead of text/html. Please advise. Thanks


    Ruby Guest

  2. #2

    Default Re: Puzzling...

    Ruby Tuesday wrote: 
    Well, both work...what error are you getting?, how are you using those?
    my results:
    Content-type: text/html


    1st line 2nd line 3rd line
    and:
    Content-type: text/plain


    1st line 2nd line 3rd line


    Osuka Guest

  3. #3

    Default Re: Puzzling...

    Oops ... I'm using them on the browser. Both of those files is in cgi-bin
    directory. I wonder why the text/plain gave me errors.

    I'm using Apache2.0.48/Ruby1.8.1. Thanks

    The error(s)
    First, a pop up windows with the message as follow:
    Some files can harm your computer. If the file information below
    look suspicious, or you do not fully trust the source, do not open or
    save this file.

    File name: ex2.rb
    File type:
    From: webserver

    Would you like to open the file or save it to your computer?

    Open Save Cancel More Info

    When I click open, a DOS window flashed quickly then dissapear.

    Thanks


    "Osuka Adartse" <net.mx> wrote in message
    news:net.mx... 
    > Well, both work...what error are you getting?, how are you using those?
    > my results:
    > Content-type: text/html
    >
    >
    > 1st line 2nd line 3rd line
    > and:
    > Content-type: text/plain
    >
    >
    > 1st line 2nd line 3rd line
    >
    >[/ref]


    Ruby Guest

  4. #4

    Default Re: Puzzling...

    Ruby Tuesday wrote:
     
    >>
    >>Well, both work...what error are you getting?, how are you using those?
    >>my results:
    >>Content-type: text/html
    >>
    >>
    >>1st line 2nd line 3rd line
    >>and:
    >>Content-type: text/plain
    >>
    >>
    >>1st line 2nd line 3rd line
    >>
    >>[/ref]
    >
    >
    >[/ref]
    Because Apache is interpreting text/html to be HTML and when it sees
    text/plain is looks to the OS for help. My guess is that when you run
    the text/plain one it tries to download the file yes? That is because
    the OS does not have a set MIME type for text/plain.

    Or something along those lines... ; )

    HTH
    Robert Guest

  5. #5

    Default Re: Puzzling...

    In my apache configuration, httpd.conf, I have the following:

    DefaultType text/plain

    I did change it to text/html and restart Apache, it's no go either.

    Any advise? Thanks

    "Robert" <org> wrote in message
    news:com... [/ref]
    cgi-bin [/ref]
    or 
    > >
    > >
    > >[/ref]
    > Because Apache is interpreting text/html to be HTML and when it sees
    > text/plain is looks to the OS for help. My guess is that when you run
    > the text/plain one it tries to download the file yes? That is because
    > the OS does not have a set MIME type for text/plain.
    >
    > Or something along those lines... ; )
    >
    > HTH[/ref]


    Ruby Guest

  6. #6

    Default Re: Puzzling...

    "Ruby Tuesday" wrote: 

    Internet Explorer is the problem. When a content type of text/plain is sent
    Internet explorer attempts to open the file using the information in the
    registry based on the file extension.

    What Internet Explorer will do is take the output and attempt to run it
    through the ruby interpreter. The same problem happens if you have
    ActiveState Perl installed and attempt to view web pages that have *.pl
    extensions and content-type text/plain.

    BTW this is incorrect.
    print "Content-type: text/html \n\n\n"

    It should be
    print "Content-type: text/html \r\n\r\n"




    Jon Guest

  7. #7

    Default Re: Puzzling...

    Ruby Tuesday wrote: 
    Thought so ;-) [/ref]
    And using IE? or I'm wrong?, that behaviour I couldn't recreate it on
    Mozilla(which does the smart thing), IE does the dialog thing, I guess
    this is caused because IE is more intimate with windows and looks up the
    file types for the .rb extension, either it saves the file or
    downloads it and then executes it(if clicking on open) hence the
    flashing dos window.

    Maybe using a .rb extension isn't that good('cos IE will look it up in
    filetypes).

    I've to wonder if you're familiar with eruby, I asked how You were using
    it 'cos as normal scripts those run fine and if I paste'em inside a
    rhtml those also worked as expected(even on IE).

    Eruby at http://modruby.net/

    look up msg id 92598 to see my setup 2.0.47 + 1.8.1
    http://www.ruby-talk.org/ruby/ruby-talk/index.shtml


    Osuka Guest

  8. #8

    Default Re: Puzzling...

    Hi Osuka, yes you are right. I'm using IE6. I'm still puzzled.

    Yes, I'm familiar with eruby. I'd rather to use mod_ruby and eruby if I can.
    But since I could not find mswin32 binaries for mod_ruby for quite
    sometimes, I had to use the CGI method. Perhaps if you can tell me where to
    get mswin32 version of the latest eruby/mod_ruby for Ruby 1.8.1 and Apache
    2.0.48, I'll take that route.

    Much Appreciated.

    PS: I downloaded Mozilla and test it. It all work out! So, what's the deal
    with IE6?
    "Osuka Adartse" <net.mx> wrote in message
    news:net.mx... [/ref]
    cgi-bin 
    > Thought so ;-) [/ref]
    or [/ref]
    > And using IE? or I'm wrong?, that behaviour I couldn't recreate it on
    > Mozilla(which does the smart thing), IE does the dialog thing, I guess
    > this is caused because IE is more intimate with windows and looks up the
    > file types for the .rb extension, either it saves the file or
    > downloads it and then executes it(if clicking on open) hence the
    > flashing dos window.
    >
    > Maybe using a .rb extension isn't that good('cos IE will look it up in
    > filetypes).
    >
    > I've to wonder if you're familiar with eruby, I asked how You were using
    > it 'cos as normal scripts those run fine and if I paste'em inside a
    > rhtml those also worked as expected(even on IE).
    >
    > Eruby at http://modruby.net/
    >
    > look up msg id 92598 to see my setup 2.0.47 + 1.8.1
    > http://www.ruby-talk.org/ruby/ruby-talk/index.shtml
    >
    >[/ref]


    Ruby Guest

  9. #9

    Default Re: Puzzling...

    Ruby Tuesday wrote: 
    In the msg 92598 is link to mod_ruby binaries, but I didn't managed to
    make'em work, but eruby is good enough for me. 
    uh? bad design? not following standards? whatever, I just know that IE
    is a risk so I just don't use it(besides tabbed browsing is addictive). [/ref]
    look there(msg id) [/ref]
    *Hint* always look on Ruby mirrors for binaries, latest eruby is 1.0.5.

    second AFAIK(or remember) Mingw32 binaries can be used with
    MSWIN(pragprog) so maybe you want to give it try(is newer and the dl is
    small 59kb)

    I guess You're using the pragprog version? then:
    http://www.ibiblio.org/pub/languages/ruby/binaries/mswin32/ext/eruby-1.0.4-i386-mswin32-1.8.zip

    If you want to try the mingw bins then:
    http://www.ibiblio.org/pub/languages/ruby/binaries/mingw/1.8/ext/eruby-1.0.5-i386-mingw32-1.8.tar.gz

    have fun ;-)
    Adartse


    Osuka Guest

  10. #10

    Default Re: Puzzling...

    "Ruby Tuesday" wrote 

    One way around the problem is to change the extension from .rb to
    cgi or remove the extension. Apache2 will execute the script based on the
    shebang line.

    mod_ruby works only on Apache 1.x




    Jon Guest

  11. #11

    Default Re: Puzzling...

    "Osuka Adartse" wrote: 

    Do you know what the difference is between erb.rb and eruby.exe?
    Is it just that eruby is compiled or are there additional features?

    --
    J. Lambert



    Jon Guest

  12. #12

    Default Re: Puzzling...

    Jon A. Lambert wrote: 
    Good question, I haven't used erb before, short and honest answer: not
    really, I don't.

    AFAIK both embed Ruby, using the taskmanager I noticed that a page that
    uses erb calls ruby.exe, but if is an eruby page it calls itself. Maybe
    someone who really knows will answer. Note the description of ERB: "ERB
    is an implementation of eRuby (embedded ruby)".

    ps: I just remembered that one "web app" that I installed, uses erb (I
    thought it was eruby cgi, but no, it's Ruby+cgi+ERB) maybe You would
    want to take a look at it, in sourceforge or RAA look for Tdiary.




    Osuka Guest

  13. #13

    Default Re: Puzzling...

    ---- Jon A. Lambert wrote: ---- 

    I'm running it right now on Apache 2.
    ___________________
    John Long
    www.wiseheartdesign.com




    John Guest

  14. #14

    Default Re: Puzzling...

    Jon A. Lambert wrote: 
    <snip> 
    Is that a Ruby thing? That certainly isn't how Perl does it. Perl does
    the following:

    print "Content-type: text/html\n\n";

    Which I believe is the standard header.
    Robert Guest

  15. #15

    Default Re: Puzzling...

    Robert wrote:
     
    >
    > <snip>

    > Is that a Ruby thing? That certainly isn't how Perl does it. Perl does
    > the following:
    >
    > print "Content-type: text/html\n\n";
    >
    > Which I believe is the standard header.[/ref]

    I'm pretty sure under the rfs your supposed to do \r\n\r\n, but I think
    most servers are setup to just look for a single blank line before
    actual content, and so they generally just look for a \n and thus the
    \n\n works. But technically it's supposed to be \r\n\r\n I think.

    Charles Comstock
    Charles Guest

  16. #16

    Default Re: Puzzling...

    Charles Comstock wrote:
     
    >>
    >>
    >> <snip>
    >> 
    >> Is that a Ruby thing? That certainly isn't how Perl does it. Perl does
    >> the following:
    >>
    >> print "Content-type: text/html\n\n";
    >>
    >> Which I believe is the standard header.[/ref]
    >
    >
    > I'm pretty sure under the rfs your supposed to do \r\n\r\n, but I think
    > most servers are setup to just look for a single blank line before
    > actual content, and so they generally just look for a \n and thus the
    > \n\n works. But technically it's supposed to be \r\n\r\n I think.
    >
    > Charles Comstock[/ref]

    Oops dunno what I was typing, I meant RFC, not rfs,

    Charles Comstock
    Charles Guest

  17. #17

    Default Re: Puzzling...


    "Charles Comstock" <wustl.edu> schrieb im Newsbeitrag
    news:c18g6f$maq$wustl.edu... 
    > >
    > >
    > > I'm pretty sure under the rfs your supposed to do \r\n\r\n, but I think
    > > most servers are setup to just look for a single blank line before
    > > actual content, and so they generally just look for a \n and thus the
    > > \n\n works. But technically it's supposed to be \r\n\r\n I think.
    > >
    > > Charles Comstock[/ref]
    >
    > Oops dunno what I was typing, I meant RFC, not rfs,
    >
    > Charles Comstock[/ref]

    Nevertheless you are right. The RFC requires \r\n sequences as line
    termination in an HTTP header. Never mind what "Perl does", it's better to
    just comply to the standard - "Better safe than sorry." :-)

    See
    http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.1

    Regards

    robert

    Robert Guest

  18. #18

    Default Re: Puzzling...

    Robert Klemme wrote: 
    >>
    >>Oops dunno what I was typing, I meant RFC, not rfs,
    >>
    >>Charles Comstock[/ref]
    >
    >
    > Nevertheless you are right. The RFC requires \r\n sequences as line
    > termination in an HTTP header. Never mind what "Perl does", it's better to
    > just comply to the standard - "Better safe than sorry." :-)
    >
    > See
    > http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.1
    >
    > Regards
    >
    > robert
    >[/ref]
    I would agree except every tutorial I have ever seen on it uses \n\n and
    not the other.
    Robert Guest

  19. #19

    Default Re: Puzzling...

    I've tried both using \n\n and \r\n\r\n on Perl and Ruby as well. Both
    resulted the same.

    When I tried it with Mozilla, the "Content-type: text/plain" works. Do you
    guys think it is the IE things? Thanks

    "Robert" <org> wrote in message
    news:com... 
    > >
    > >
    > > Nevertheless you are right. The RFC requires \r\n sequences as line
    > > termination in an HTTP header. Never mind what "Perl does", it's better[/ref][/ref]
    to 
    > I would agree except every tutorial I have ever seen on it uses \n\n and
    > not the other.[/ref]


    Ruby Guest

  20. #20

    Default Beginner here, have some questions

    Ruby beginner here. Heard of it before and on a whim decided to check
    it out a couple of days ago and I love it. I friggin love it.
    I'm doing stuff that would take me a while to figure out with other
    languages' syntax. I've never seen a language that looks so "clean."

    Anyway, I have some questions I couldn't find in the FAQ

    sample code:

    x = 2
    puts x

    Now, is "puts" a class or instance method of Object? What about "x"?
    Is that a class or instance variable of an Object?
    When you run a Ruby program, is the program an instance of Object?



    Sang Guest

Page 1 of 3 123 LastLast

Similar Threads

  1. Printers' Position on PDF Puzzling
    By Doug_Katz@adobeforums.com in forum Adobe Acrobat Macintosh
    Replies: 9
    Last Post: November 16th, 01:41 AM
  2. puzzling issue with numeric stepper
    By amarmabbu in forum Macromedia Flash Actionscript
    Replies: 1
    Last Post: February 29th, 10:18 PM
  3. Puzzling performance issue?
    By Eric in forum Informix
    Replies: 16
    Last Post: December 2nd, 09:07 AM
  4. puzzling deadlock
    By Robert in forum Oracle Server
    Replies: 1
    Last Post: September 25th, 09:38 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139