Rhodes Tutorial ======== This tutorial describes how to use Rhodes and RhoSync to build native mobile apps for all shipping smartphones. Specifically it describes how to write Rhodes controllers and templates and how to write RhoSync source adapters to sync data from backend apps to the device. The architecture of this is shown [here](https://img.skitch.com/20110111-1snnuchj3ph1hu41cafkb23jng.png). Install Rhodes -------------- Install and Setup Rhodes following instructions [here](install). Generating A Rhodes Application ------------------------------- The first step is to generate the application and base files. First we will generate an application called StoreManager with the following command: :::term $ rhodes app storemanager http://localhost:9292/application This will generate an application directory called "storemanager" with several files. Note also that the third argument above is the URL to the RhoSync server data source (required if you want to do synchronized data as we describe in the next section). Specifically it will set the rhoconfig.txt file to have the following option: syncserver = 'http://localhost:9292/application' If you do not need synchronized offline data, you can leave the third argument out. The default home screen of the app is defined in the storemanager/app/index.erb file. You can edit the HTML there to create what your app displays. You can link to other HTML files and ERB files from there with standard HTML techniques. Then you can build your app with rake tasks. For example, to build for the iPhone and run the simulator, type the following commands: :::term $ cd storemanager $ rake run:iphone To build for other platforms/simulators, you execute the appropriate rake tasks, such as "rake run:bb" to run it on the BlackBerry emulator. To see all possible rake tasks: :::term $ rake -T Generating Models ----------------- Now that your app compiles and runs, you can start adding models and controllers. When the model is generated, Rhodes will also create files for a standard UI for displaying and editing the model. This follows the standard model-view-controller paradigm. Let's generate a model called "product" and give it some attributes. :::term $ cd storemanager $ rhodes model product brand,name,price,quantity,sku Generating with model generator: [ADDED] app/Product/index.erb [ADDED] app/Product/edit.erb [ADDED] app/Product/new.erb [ADDED] app/Product/show.erb [ADDED] app/Product/index.bb.erb [ADDED] app/Product/edit.bb.erb [ADDED] app/Product/new.bb.erb [ADDED] app/Product/show.bb.erb [ADDED] app/Product/product_controller.rb [ADDED] app/Product/product.rb [ADDED] app/test/product_spec.rb Editing Rhodes Views -------------------- You can edit the generated ERB files to customize the HTML as you see fit. Typically you will provide links to the model index page from the home screen. Below is the generated top level index.erb file for the Store Manager app (app/index.erb). :::ruby