Warning Older Docs! - You are viewing documentation for a previous released version of RhoMobile Suite.

Rhodes Command Line

This section describes how to use Rhodes from the command line (as opposed to using RhoStudio, an Eclipse-based IDE) to build native mobile apps for all shipping smartphones. Specifically it describes how to write Rhodes controllers and templates and refers to the RhoConnect tutorial on how to write RhoConnect source adapters to sync data from backend apps to the device. The architecture of this is shown here.

Install Rhodes

Install and Setup Rhodes following instructions here.

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:

$ 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 RhoConnect 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:

$ 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:

$ 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.

$ 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).

<div data-role="page" data-url="<%= Rho::RhoConfig.start_path %>/">

  <div data-role="header" data-position="inline">
    <h1>Storemanager</h1>
    <% if SyncEngine::logged_in > 0 %>
        <a href="<%= url_for :controller => :Settings, :action => :do_sync %>" class="ui-btn-left" data-icon="refresh">Sync</a>
        <a href="<%= url_for :controller => :Settings, :action => :logout %>" class="ui-btn-right" data-icon="star">Logout</a>
    <% else %>
        <a href="<%= url_for :controller => :Settings, :action => :login %>" class="ui-btn-right" data-icon="star">Login</a>
    <% end %>
  </div>

  <div data-role="content">
    <ul data-role="listview">
      <li>
        <a href="#">Add Links Here...</a>
      </li>
    </ul>
  </div>

  <div data-role="footer" data-position="inline">
    <p>it is optional part of page..</p>
  </div>

</div>

To provide a link to the Product model’s index page and templates you can replace the list item with the title “Add links here” with:

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

NOTE: You can edit this top level page or any of the other pages with any arbitrary HTML you wish. We don’t attempt to teach you HTML or Ruby here but there are many good external references for both topics.

Doing More With Rhodes

See the comprehensive and exhaustive Rhodes Developer Reference for details on all Rhodes capabilities.

Code samples of each and every Rhodes capability are in the Rhodes API samples.

You should take a look at the Rhodes 2.0 training webinar.

There is a technical FAQ that describes how to perform certain specific tasks in Rhodes.

The following sections describe how to add synchronized data to our app with RhoConnect.

Adding Synchronized Data to Your App with RhoConnect

To add synchronized data to your application, see the RhoConnect Tutorial. Also check out the RhoConnect training video.

More Info

There are training webinars on various Rhomobile related topics held weekly. Videos of these are on the Rhomobile Vimeo channel.

There is also the following book on Rhomobile.

For more questions, write to us or join the Rhomobile Google Group and post.

Back to Top