cgi icon indicating copy to clipboard operation
cgi copied to clipboard

Can no longer use [] on cgi?

Open rubyFeedback opened this issue 4 months ago • 0 comments

Using this in a .cgi page:

require 'cgi'

cgi = CGI.new
value = cgi['field_name'] # => "123"
cgi['flowerpot'] # => ""
fields = cgi.keys # => [ "field_name" ]

cgi.has_key?('field_name') # => true
cgi.include?('field_name') # => true
cgi.include?('flowerpot') # => false

I am using the gem via gem install cgi by the way.

The error is:

misc.cgi:12:in '<main>': undefined method '[]' for an instance of CGI (NoMethodError)

cgi['name'] 

Is the [] method gone? Has something changed in the code?

I used to have a local copy of cgi and using that, I think [] and .params worked. But now it does not work. Has the recent change in ruby caused this? Guess it is time to finally switch to sinatra anyway - at the least param handling works there. But it is strange how ruby has so many small issues lately. Can we go back to oldschool enginering again?

rubyFeedback avatar Aug 09 '25 23:08 rubyFeedback