[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

ruby website code ignores function

Edward

9/8/2006 2:16:00 AM

When I run the following script as a web page, it ignores the output of
my function and doesn't print the "test2" as if there is a problem with
the function. How can I fix this? I pasted the code below.

View Example: http://www.ta.../learnruby/nof...

Thanks,

Edward Tanguay
All my projects: http://www.ta...

=====================================

#!/usr/bin/ruby
print "Content-type: text/plain\n\n"

3.times { print "Hello World\n" }
print "test1"
print sayHello("Jim")
print "test2"

def sayHello(name)
result = "Hello" + name
return result
end

2 Answers

Ara.T.Howard

9/8/2006 2:31:00 AM

0

Edward

9/8/2006 3:18:00 AM

0

right, I didn't have ruby installed locally (windows) but I can ssh
onto the site and test it there, THANKS for the tip!

Edward Tanguay
All my projects: http://www.ta...


ara.t.howard@noaa.gov wrote:
> On Fri, 8 Sep 2006, Edward wrote:
>
> > When I run the following script as a web page, it ignores the output of
> > my function and doesn't print the "test2" as if there is a problem with
> > the function. How can I fix this? I pasted the code below.
> >
> > View Example: http://www.ta.../learnruby/nofunction.rb
> >
> > Thanks,
> >
> > Edward Tanguay
> > All my projects: http://www.ta...
> >
> > =====================================
> >
> > #!/usr/bin/ruby
> > print "Content-type: text/plain\n\n"
> >
> > 3.times { print "Hello World\n" }
> > print "test1"
> > print sayHello("Jim")
> > print "test2"
> >
> > def sayHello(name)
> > result = "Hello" + name
> > return result
> > end
>
> as with cgis in any language, always, always, always make sure they can run
> from the command line, preferably as the webuser. doing so in this can shows:
>
> harp:~ > cat a.rb
> #!/usr/bin/ruby
> print "Content-type: text/plain\n\n"
>
> 3.times { print "Hello World\n" }
> print "test1"
> print sayHello("Jim")
> print "test2"
>
> def sayHello(name)
> result = "Hello" + name
> return result
> end
>
>
>
> harp:~ > ruby a.rb </dev/null
> Content-type: text/plain
>
> Hello World
> Hello World
> Hello World
> a.rb:6: undefined method `sayHello' for main:Object (NoMethodError)
>
>
> in ruby, functions must be defined before they are used.
>
> kind regards.
>
> -a
> --
> what science finds to be nonexistent, we must accept as nonexistent; but what
> science merely does not find is a completely different matter... it is quite
> clear that there are many, many mysterious things.
> - h.h. the 14th dalai lama