從http://www.rubyinside.com/nethttp-cheat-sheet-2940.html你得到你可以做到以下幾點:
在您的文件頂部添加:
require "net/http"
require "uri"
require 'json'
然後在您的控制器中或幫手:
#set the uri
uri = URI.parse("http://my.site.com/uri")
#set the post params and get the respons
response = Net::HTTP.post_form(uri, {"first_param" => "my param", "second_param" => "another param"})
#get the json info
data = JSON.parse(response.body)
#set result to an ActiveRecord (maybe there is a better way to do this, I guess it depends on the response you get
@something = Mymodel.new
@something.name = data["name"]
...
@something.save
希望它有幫助!