can't override a cgi function, please help

Discussion in 'Ruby' started by Cere Davis, Jul 12, 2004.

  1. Cere Davis

    Cere Davis Guest

    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

    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
     
    Cere Davis, Jul 12, 2004
    #1
    1. Advertising

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


    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
     
    Gavin Sinclair, Jul 12, 2004
    #2
    1. Advertising

  3. Cere Davis

    Cere Davis Guest

    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
    >
    >
    >
     
    Cere Davis, Jul 12, 2004
    #3
  4. Cere Davis

    Cere Davis Guest

    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
    >>
    >>
    >>
     
    Cere Davis, Jul 12, 2004
    #4
  5. il Mon, 12 Jul 2004 15:32:15 -0700, Cere Davis <>
    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.


    I think oyu messed up something. Anyway you don't jave to use 'puts'
    you just should return a string from the method
     
    gabriele renzi, Jul 13, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    3,452
    Truong Hong Thi
    Dec 9, 2005
  2. KK
    Replies:
    2
    Views:
    728
    Big Brian
    Oct 14, 2003
  3. Replies:
    2
    Views:
    972
    Bengt Richter
    Aug 1, 2005
  4. Jer A
    Replies:
    2
    Views:
    186
    Dan Zwell
    May 24, 2007
  5. mjl69
    Replies:
    1
    Views:
    129
    Alan Mead
    Feb 13, 2005
Loading...

Share This Page