Extending RhoConnect Application with custom routes === You can provide custom routes support in your RhoConnect application and utilize all the powerful features of the typical Sinatra app. To do this, simply define your routes in the corresponding controller class. Endpoint URL for your routes will be relative to the controller's root. The following example illustrates how to add a sample `my_custom_route' to the Product Controller: :::ruby class Product < Rhoconnect::Controller::Base get '/my_custom_route', :login_required => true do send_file 'public/my_file.png' end end This route will have the following URL : GET '/app/v4/Product/my_custom_route' The above custom route implementation will respond to client's GET request, verifies the current_user (which will be extracted from the RHoConnect session cookie and checked for validity by the `:login_required` condition) and returns a static PNG file (which can be later used in BLOB syncs) Using the New Custom route in BLOB syncs --- After you create the new custom routes you can reference and use them from standard Rhodes applications. For example, suppose you have a Rhodes app with a Product model. To use a custom route in BLOB syncs, define the following property in the Rhodes Product model (file: `app/Product/product.rb`): :::ruby # The model has already been created by the framework, and extends Rhom::RhomObject # You can add more methods here class Product include Rhom::PropertyBag # Uncomment the following line to enable sync with Product. enable :sync #add model specific code here property :my_custom_blob_field, :blob, :overwrite end To see the static image, modify the `app/Product/show.erb` file for the Product model in your Rhodes application: :::html
  • My Static Field Image
  • Then, modify your RhoConnect source adapter model (in `rhoconnect_app/models/ruby/product.rb`) to provide BLOB's url for the `my_custom_blob_field`: :::ruby def query(params=nil) parsed = JSON.parse(RestClient.get("#{@base}.json").body) @result={} parsed.each do |item| item["product"]["my_custom_field-rhoblob"] = "http://localhost:9292/app/v4/Product/my_custom_route" @result[item["product"]["id"].to_s] = item["product"] end if parsed end This way, your `my_custom_field` would be getting the BLOB image data from the custom route defined in your RhoConnect Source Adapter Controller. For more information on BLOB syncs, see [this section](http://docs.rhomobile.com/rhoconnect/blob-sync).