This is soooo driving me crazy!
I'm just trying to override the checkbox function on the CGI ruby library and can not. Can someone tell me what I am doing wrong?
Simply:
require 'cgi'
class << CGI
def checkbox(name="",val=nil,checked=nil)
puts "asdf"
puts @params[name]
end
end
cgi=CGI.new('html3')
cgi.out() do
cgi.html() do
cgi.body() do
cgi.form("get") do
cgi.checkbox('box','true',"checd") +
cgi.br +
cgi.submit("Okey Dokey?")
end
end
then I run
!./mycgipro stuff=dddd
but it doesn't print out the "asdf" garbage that I overroad the function with...
What's up? Does anyone know how to do this. I'm new to overriding in Ruby.
Related to this is the "input(attributes)" function but I can't seem to trace what this is doing or where the input function even comes from.
Thanks,
Cere
You're creating/overriding a *class* method of CGI, not an *instance*
method. Try -- with the code above -- calling 'CGI.checkbox(...)' and
see what happens.
Do this:
class CGI
def checkbox(...)
...
end
end
Cheers,
Gavin
···
On Tuesday, July 13, 2004, 8:02:35 AM, Cere wrote:
This is soooo driving me crazy!
I'm just trying to override the checkbox function on the CGI ruby
library and can not. Can someone tell me what I am doing wrong?
Simply:
require 'cgi'
class << CGI
def checkbox(name="",val=nil,checked=nil)
puts "asdf"
puts @params[name]
end
end
cgi=CGI.new('html3')
cgi.out() do
cgi.html() do
cgi.body() do
cgi.form("get") do
cgi.checkbox('box','true',"checd") +
cgi.br +
cgi.submit("Okey Dokey?")
end
end
end
end
That was actually the first thing I tried but I figured I would just trial and error my way through soem Ruby syntax and class << CGI was my next guess. Thanks for clarifying the difference. As it happens though, this makes no difference. Again, I think this may have something to do with the input(attributes) function at the bottom of the original cgi class. Something about these variables get precidence over any overriding variables???
Me no understand...
···
You're creating/overriding a *class* method of CGI, not an *instance*
method. Try -- with the code above -- calling 'CGI.checkbox(...)' and
see what happens.
Do this:
class CGI
def checkbox(...)
...
end
end
Cheers,
Gavin
Oops. I spoke a little too soon. I do get something:
An undefined method error on checkbox.
So I need to define this method as public or something?
How would I overrride a checkbox instance without calling having to call a new CGI class? Ideally, I would just like it to be overriden in the main CGI class and inherited in when I make a CGI.new.
Thanks,
cere
Cere Davis wrote:
···
That was actually the first thing I tried but I figured I would just trial and error my way through soem Ruby syntax and class << CGI was my next guess. Thanks for clarifying the difference. As it happens though, this makes no difference. Again, I think this may have something to do with the input(attributes) function at the bottom of the original cgi class. Something about these variables get precidence over any overriding variables???
Me no understand...
You're creating/overriding a *class* method of CGI, not an *instance*
method. Try -- with the code above -- calling 'CGI.checkbox(...)' and
see what happens.
Do this:
class CGI
def checkbox(...)
...
end
end
Cheers,
Gavin
I think oyu messed up something. Anyway you don't jave to use 'puts'
you just should return a string from the method
···
il Mon, 12 Jul 2004 15:32:15 -0700, Cere Davis <cere@u.washington.edu> ha scritto::
Oops. I spoke a little too soon. I do get something:
An undefined method error on checkbox.
So I need to define this method as public or something?
How would I overrride a checkbox instance without calling having to call
a new CGI class? Ideally, I would just like it to be overriden in the
main CGI class and inherited in when I make a CGI.new.