1

I'm new to Ruby and Rails and am to develop and write a simple connector to use an API Service for my Rails APP. I have a connector which uses CGI class with RUby. Now I want to implement the same on rails platform. How will it go? What are the alternative classes (or gems) that provide similar functionality as of CGI for rails

As for instance I have this code :

cgi = CGI.new
if cgi.params['jsonString']!=""
    data=cgi.params['jsonString'].to_s
    data.delete! '\\'
    data.delete! '['
    data.delete! ']'
    data=data[1..-1]
    data=data[0..-2]
    shieldsquare_service_url = 'http://' + $_ss2_domain + '/getss2data'
    shieldsquare_request = JSON.parse(CGI::unescape(data))
    shieldsquare_request["sid"] = $_sid
    shieldsquare_request["host"] = ENV[$_ipaddress]
    shieldsquare_post_data = JSON.generate(shieldsquare_request)
    if $_async_http_post== true
        error_code=shieldsquare_post_async shieldsquare_service_url,               shieldsquare_post_data,$_timeout_value.to_s
    else
        error_code=shieldsquare_post_sync shieldsquare_service_url, shieldsquare_post_data, $_timeout_value
    end
end

Please Guide me on this topic

EverJay Dihenkar
  • 143
  • 1
  • 1
  • 10

1 Answers1

1

CGI and rails are completely different. Here is CGI on wikipedia: https://en.wikipedia.org/wiki/Common_Gateway_Interface

In case of rails, start by looking at Rack:
http://codefol.io/posts/What-is-Rack-A-Primer
What is Rack middleware?

So effectively when the request hits rails (or sinatra or whatever you are using that conforms to rack) it's in a standard format. Rails only has to worry about that. Not worrying is usually good and means that you can focus on the app. The downside of it is that you have to learn the conventions the framework you are using follows to be effective in using it.

Also take a quick look at: Rails vs Ruby CGI

Community
  • 1
  • 1
Mircea
  • 10,216
  • 2
  • 30
  • 46