如何在没有Rhosync或RhoConnect的情况下使用Rhodes? [英] How to use Rhodes without Rhosync or RhoConnect?

查看:96
本文介绍了如何在没有Rhosync或RhoConnect的情况下使用Rhodes?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我们可以使用直接Web服务在不使用Rhosync或Rhoconnect的情况下使用Rhodes同步数据,但是我在这里有点困惑将代码放置在何处以及如何初始化它.有人可以帮我举个小例子吗?

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?

在此先感谢.

推荐答案

我明白了,它对我有用.

I got it and it works for me.

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

这篇关于如何在没有Rhosync或RhoConnect的情况下使用Rhodes?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆