2015-07-19 33 views
0

我是Ruby和Rails的新手,我正在開發和編寫一個簡單的連接器來爲我的Rails APP使用API​​服務。我有一個與RUby一起使用CGI類的連接器。現在我想在rails平臺上實現相同的功能。它將如何去?什麼是替代類(或寶石)提供類似的功能CGI鋼軌Rails框架上的Ruby CGI代碼

至於比如我有這樣的代碼:

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 

請指導我關於這個主題

回答

0

CGI和軌道是完全不同的。 這裏是維基百科CGI:
http://codefol.io/posts/What-is-Rack-A-Primer
What is Rack middleware?

那麼有效,當請求命中軌(或屈或任何你正在使用: https://en.wikipedia.org/wiki/Common_Gateway_Interface

在軌的情況下,通過查看機架開始符合機架)標準格式。 Rails只需要擔心這一點。不用擔心通常很好,這意味着您可以專注於應用程序。它的不足之處是你必須學習你使用的框架的約定,纔能有效地使用它。

也採取快速瀏覽一下: Rails vs Ruby CGI

+0

好了,應該怎麼上面的代碼看起來on Rails的? –