Testing Sync From the Client

To test to make sure the sync is working, we need to create a basic RhoMobile application. This can be done either through the command line interface or through RhoStudio.

Creating the RhoMobile client Application

1. Open your terminal or preferred command line interface.

2. Run the following command without the brackets.

$ rhodes app <appname>

1. Open RhoStudio

2. Select File / New Project / RhoMobile Application

3. After choosing an application name click Finish

Adding the Product Model

While in the command line, run the following command without the brackets.
$ rhodes model <modelname> <comma,seperated,list,of,attributes>

1. While in RhoStudio, right click on the project you just created

2. Choose New / RhoMobile Model

3. Enter Product in the Model name field

4. Enter name,brand,quantity,price in the Model attributes field

Pay attention to spelling of the model and attributes, as the sample code is assuming that it will match exactly to the JSON object coming from the back-end.

Enabling Sync

1) Open the folder app\Product and edit the file product.rb

2) Uncomment the line enable :sync line.

# 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

Adding Product views

1) Open the file app\index.erb

2) Replace the line:

<li><a href="#">Add link here...</a></li>


<li><a href="Product">Product</a></li>

Configuring your SyncServer

Make sure your server URL is configured in the Rhomobile app. If your server is running on YourIPAddress with the port 9292, the following line should be at the bottom of your corresponding Rhodes app, rhoconfig.txt:

syncserver = 'http://YourIPAddress:9292'
If you are using Android, syncserver cannot be set to localhost, you must use your machine's local IP Address. Ex: 192.168.x.x

Syncing Data

To sync with the RhoConnect server, the Rhodes client must log in. The Rhodes generated app includes some screens for login and other common functions, which you will typically modify to suit the design of your application. The generated UI is useful since it allows you to focus on the core functionality of your application before implementing the important, but mundane, details of user authentication and settings.

1. From the home page in the Rhodes app, click on the login button in the upper right corner. Alternatively, you can click on the tool icon at the bottom of the screen to go to the Settings screen.

2. Login using any name & password. The generated code allows any login, but you can modify that in application.rb.

App Home Page

App Login Page

3. If login is successful, you will see a Client ID in the settings screen. The ClientID is generated the first time you log in and is stored in the client database. It serves as a unique identifier which is required for rhoconnect. (Note: this value will persist across logins, but if you reset the client database or the user re-installs the app, a new ClientID will be generated.)

4. Sync is triggered automatically. Click on the home icon and then select “Products” and you should see the list of product records from the server.

App Settings Page With Client ID

List of Products on Local Storage

5. You can now add, modify or delete products to your app locally and then sync them to the Rhostore back-end.

Create New Product Page

Rhostore Before Sync

Rhostore After Sync

6. You can also simulate changes that occur on the backend, by using the CRUD operations from your browser. These changes will not appear on the device for at least 5 minutes. This is due to the default setting for the RhoConnect application to query the backend for updates. You can modify this by changing the `poll_interval` setting in the `settings\setting.yml` file in the RhoConnect application.

Now that you have your RhoConnect server successfully syncing to your back-end application, you’re ready to move on to more advanced topics using RhoConnect such as PUSH notifications, RhoConnect plug-ins, and sync conflict resolution to name a few. For more information on these and other topics, refer to our RhoConnect Guides.

For a tutorial on deploying your RhoConnect app in the cloud, continue on to the next page.