Get and Post at the same time

  • Thread starter Douglas Livingstone
  • Start date
D

Douglas Livingstone

Here's a script to retrieve Get and Post as the same time. I've had a
look for one as I needed it, but didn't find anything.

If someone finds it useful, great. If someone can tell me how it is
terrible Ruby code and how to make it better, that would be cool too
:)

Douglas

class GetPostRequest

include Singleton

attr_reader :raw_get, :raw_post
attr_reader :get, :post, :request

# data from QUERY_STRING and $stdin
def initialize
@get = @post = Hash.new
if ENV['QUERY_STRING']
@raw_get = ENV['QUERY_STRING']
@get = CGI::parse(@raw_get)
end
if ENV['REQUEST_METHOD'] == 'POST'
@raw_post = $stdin.gets.strip
@post = CGI::parse(@raw_post)
end
@request = @post.merge(@get) # get wins
end

# combined Get and Post
def [](key)
@request[key]
end

end
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top