Puzzling...

R

Ruby Tuesday

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
 
O

Osuka Adartse

Ruby said:
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
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
 
R

Ruby Tuesday

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
 
R

Robert

Ruby said:
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
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
 
R

Ruby Tuesday

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
 
J

Jon A. Lambert

Ruby Tuesday said:
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.

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"
 
O

Osuka Adartse

Ruby said:
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. Thought so ;-)

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

Ruby Tuesday

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?
 
O

Osuka Adartse

Ruby said:
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.
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.
Much Appreciated.

PS: I downloaded Mozilla and test it. It all work out! So, what's the deal
with IE6?
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).*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
 
J

Jon A. Lambert

PS: I downloaded Mozilla and test it. It all work out! So, what's the deal
with IE6?

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
 
J

Jon A. Lambert

O

Osuka Adartse

Jon said:
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?
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.
 
R

Robert

Jon said:
"Ruby Tuesday" wrote:
BTW this is incorrect.
print "Content-type: text/html \n\n\n"

It should be
print "Content-type: text/html \r\n\r\n"
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.
 
C

Charles Comstock

Robert said:
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.

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
 
C

Charles Comstock

Charles said:
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

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

Charles Comstock
 
R

Ruby Tuesday

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
 
S

Sang Kim

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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top