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

Rhodes Application Generator

You can use RhoStudio to create Rhodes applications and models in an Eclipse-like environment.

You can also use the Rhodes generator utility from the command line to create Rhodes applications, models, and tests (specs).

Generating a Rhodes Application from RhoStudio

In RhoStudio, select File->New->Project…

The New Project window opens. Select the Rhodes application wizard and click the Next button.

Enter the name for your Rhodes application in Project name; in this case, “storemanager”. You may specify a specific folder for your destination where your project is stored, by default, the destination is your RhoStudio workspace folder. Then press the Finish button.

After pressing the Finish button, you’ll see the Rhodes app generator script output in the output console (Rhomobile build console).

The generated application has the following directory structure and files.

storemanager/
    Rakefile
    build.yml
    rhoconfig.txt
./app:
    application.rb
    index.erb
    layout.erb
    loading.html
    loading.png
./app/Settings:
    controller.rb   
    home.erb    
    index.erb   
    login.erb   
    reset.erb   
    wait.erb
./app/helpers:
    application_helper.rb
    browser_helper.rb
./icon:
    <default application icons; modify these to have your own app icon>
./public:
./public/css:
    <default set of css for different platforms>
./public/images:
    <default images used by js libraries>
./public/jquery:
    <jQuery js script with some rhomobile fixes>
./public/jqmobile:
    <jQuery Mobile js script with some rhomobile fixes>
./public/js:
    <default js libraries>

Adding a Model to a Rhodes Application from RhoStudio

Rhodes applications support a Model-View-Controller (MVC) pattern.  To start our application, we will generate a Model. To generate a Rhodes model and create the associated Controller and View templates, right-click on the application project in the Project Explorer and select New->RhoMobile model.

In the Model Information window, enter the name for your model: in this case, Product.

Do not use the following for model names: Config, Settings, helpers, test, Client, Sync, or any built-in Ruby class name. It is good programming practice to avoid using generic names, such as client, or time, or print.

Also enter the Model attributes as a string with no spaces and each attribute separated by a comma: in this case, name,brand,price,quantity,sku. (Whitespaces at the field name beginning and end will be trimmed and whitespaces in the middle of the field name will be replaced with an underscore character.)

After pressing the Finish button, you’ll see the RhoMobile model generator script output in the output console (Rhodes build log console).

You should now see a ‘Product’ folder below the ‘app’ folder in your storemanager application. These files constitute the Model, Views and Controller file for the Product Model we just created. The files are organized as follows:

This will generate the following files in the folder app/Account:

  • app/Product/index.erb - the html view template to display the list of objects
  • app/Product/edit.erb - the html view template to edit an object
  • app/Product/new.erb - the html view template to supply values to create a new object
  • app/Product/show.erb - the html view template to displays the selected object
  • app/Product/product_controller.rb - contains the the business logic for the model, the basic CRUD actions: index, new, create, edit, update and delete.
  • app/Product/product.rb - contains the Product model definition. Since we are using the default PropertyBag definition, we don’t need to modify this file any further.

A placeholder for test specs will be generated in the app/test folder:

  • app/test/product_spec.rb - placeholder for Account test specs

Generating A Rhodes Application and Model

You can generate your Rhodes application and model from the command line.

Generating a Rhodes Application from the Command Line

You can pass your application name to the rhodes app command as a parameter. The Rhodes utility will generate a default directory structure for your application, with default code for the generated files.

Usage: rhodes app name [options] [args]

Generate a new rhodes application.
Options:
 --norhoconnect - don't include rhoconnect-client in application

Required:
  name        - application name

args (optional):
  syncserver  - url to the source adapter (i.e. "" or "http://myacct.rhohub.com/apps/myapp/sources/")
  zip_url     - optional url to zipfile download of bundle (this can be your RhoHub Bundle URL)

options:
    -p, --pretend                    Run, but do not make any changes.
    -f, --force                      Overwrite files that already exist.
    -s, --skip                       Skip files that already exist.
    -d, --delete                     Delete files that have previously been generated with this generator.
        --no-color                   Don't colorize the output
    -h, --help                       Show this message
        --debug                      Do not catch errors

Adding a Model to Your Rhodes Application from the Command Line

Once you have generated your application, you can add a model to it, and the model can have attributes. For example, if you have a store application, you can add a model named product, and attributes like brand, name, price, and quantity.

Usage: rhodes model [options] [args]

Generate a new model for a rhodes application.

args:
  name        - model name
  attributes  - list of one or more attributes (i.e. name,industry,progress), NO spaces between attributes

options:
    -p, --pretend                    Run, but do not make any changes.
    -f, --force                      Overwrite files that already exist.
    -s, --skip                       Skip files that already exist.
    -d, --delete                     Delete files that have previously been generated with this generator.
        --no-color                   Don't colorize the output
    -h, --help                       Show this message
        --debug                      Do not catch errors

For example, here is the command to generate a model named account, with the attributes name and industry.

$ cd myspace
$ rhodes model account name,industry

Adding a Native extension to Your Rhodes Application from the Command Line

Once you have generated your application, you can add a native extension to it.

Usage: rhodes extension [args]

Generate a new native extension for a rhodes application.

args:
  name        - extension name

For example, here is the command to generate a model named account, with the attributes name and industry.

$ cd myspace
$ rhodes extension Nanovisor

Adding Test Framework

To add a test framework to the application:

Usage: rhodes spec

Add test framework to a rhodes application.

For example:

$ cd myspace
$ rhodes spec

This will generate the following files in the app folder:

  • SpecRunner/controller.rb - contains index action, which start all tests
  • SpecRunner/index.erb - the template to display tests results
  • mspec.rb - contain all mspec required files
  • spec_runner.rb - contain spec framework initialization and generate list of spec files

If you are going to use mspec, then add mspec and fileutils extensions to your application’s build.yml file:

extensions: ["mspec", "fileutils"]

To run the tests you need to add a link to the SpecRunner controller in your index.erb: :::html

  • Run tests
  • Once you click the link a summary of the results with number of passing/failing tests will be displayed on the screen.

    Back to Top