1

I know we can sync data using rhodes without Rhosync or Rhoconnect by using direct web service, but I'm here little bit confuse where to place that code for webservice call and how do we initialize it. Can anyone help me with small example?

Thanks in Advance.

4

2 に答える 2

3

私はそれを手に入れました、そしてそれは私のために働きます。

class ProductController < Rho::RhoController
  include BrowserHelper

    # GET /product
  def index
    response =  Rho::AsyncHttp.get(:url => "example.com/products.json",
     :headers => {"Content-Type" => "application/json"})
     @result = response["body"] 

    render :back => '/app'
  end

    # GET /product/{1}
  def show
    id =@params['id']
    response =  Rho::AsyncHttp.get(:url => "example.com/products/"+ id +".json",
    :headers => {"Content-Type" => "application/json"})

    @result = response["body"]
  end

   # GET /product/new
  def new
    @product = product.new

    render :action => :new, :back => url_for(:action => :index)
  end

    # GET /product/{1}/edit
  def edit
    id =@params['product_id'].to_s
    response =  Rho::AsyncHttp.get(:url => "example.com/products/#{id}.json",
    :headers => {"Content-Type" => "application/json"})

    @result = response["body"]
  end

    # POST /product/create
  def create
    name = @params['product']['name']
    price = @params['product']['price']
    body = '{"product" : {"name" : "'+ name +'","price" :"'+ price +'"  } }'

    @result =  Rho::AsyncHttp.post(:url => "example.com/products.json",
    :body => body, :http_command => "POST", :headers => {"Content-Type" => "application/json"})  

    redirect :action => :index
  end

    # POST /product/{1}/update
  def update

    name=@params['product']['name']
    price=@params['product']['price']

    body = '{"product" : {"name" : "' + name + '","price" :"' + price + '"  } }'
    id = @params["product_id"].to_s

    response =  Rho::AsyncHttp.post(:url => "example.com/products/#{id}.json",
    :body => body, :http_command => "PUT",:headers => {"Content-Type" => "application/json"})

    redirect :action => :index
  end

    # POST /product/{1}/delete
  def delete
    id = @params["product_id"].to_s
    response =  Rho::AsyncHttp.post(:url => "example.com/products/#{id}.json",
    :http_command => "DELETE", 
    :headers => {"Content-Type" => "application/json"})  

    redirect :action => :index  
  end
end
于 2012-07-24T10:59:32.973 に答える
0

httpサーバーリクエストの最も簡単な形式は次のとおりです。

Rho::AsyncHttp.get(
  :url => "http://www.example.com",
  :callback => (url_for :action => :httpget_callback)
)

ここでhttpget_callback、はコントローラーのコールバックメソッドの名前です。

詳細については、Rhodesの公式ドキュメントをご覧ください。

于 2012-09-04T16:49:28.087 に答える