CopyPastehas never been so tasty!

Mobile Application Development with Ruby and Rails using Rho

by anonymous

  • 0
  • 0
  • 0



Mobile apps are gaining a lot of traction, especially amongst the younger generation. Let's see how to build mobile apps using the tools we are already familiar with, i.e. Ruby and Rails.



What is Rhomobile?


 Rhomobile is a suite of open source frameworks which can be used to build native mobile applications.Out of those we are particularly interested in Rhodes; it is a Ruby framework for building mobile applications, quite similar to how Rails is for building web applications.



Why Rhodes?


Rhodes lets us quickly build native mobile applications for all major smartphones: Android (2.1 and higher), iPhone/iPad (iOS 3.0 and higher), BlackBerry (BB OS 4.6 and higher), Windows Mobile (6x Professional, 6.0 Standard), Windows7 Phone and Symbian. The best part is, it is cross-platform, so we need to code only once and the same code can be compiled for all supported platforms. It enables us to build applications for mobile devices using Ruby, HTML, CSS and Javascript, instead of languages such as Objective-C. Similar to Rails, it is a MVC framework, so the learning curve is pretty small if you are already familiar with Ruby and Rails. It also provides access to a lot of native device capabilities like  Alarm, Alert, Bluetooth, Camera, etc. You can check out the full list  here.



Getting Started


The  official documentation is quite comprehensive and does a pretty good job of explaining all features in detail. So, we will just look at the basic stuff that will be required in most mobile apps.


Installation: Install via rubygems gem install rhodes or install  RhoStudio for a full IDE. You will also need to install JDK and the  SDK of all devices that you want to build for.


Rhodes Configuration: Run rhodes-setup command to setup SDK paths for the various platforms. It will display its best guess as to where the SDK is. You can then enter a new location, or leave it blank to use the suggestion. If you are not building for a specific platform (for example, you can’t build for the iPhone on Windows), you can leave that SDK location blank.


If you are using RhoStudio, you can also set the SDK paths in RhoStudio Preferences.


Creating a new app: Run rhodes app <appname> command to generate a new app. Or create a new


project from the RhoStudio menu. It generates a basic application structure somewhat similar to Rails, but model, controller and its associated views are grouped and placed in a single folder. Please refer to the  Rhodes generatordocumentation for more detailed information about the Rhodes directory


structure. Similarly to app, a model can be generated from command line using rhodes model


<model_name> <model_attributes> or, from RhoStudio.




Similar to ActiveRecord in Rails, Rhodes uses Rhom as a mini database object mapper. It provides a high level interface to make it very powerful and simple to use a local database. The database is SQLite on all platforms except BlackBerry where it is HSQLDB.


Rhom currently supports two model types: Property Bag (default) and Fixed Schema


Property Bag:All data is stored in a single table using the object-attribute-value pattern also referred toas the  Entity-attribute-value model.


Fixed Schema: Each model has a separate database table and each attribute exists as a column in thetable, like a relational database.



CSS & JavaScript


Rhodes supports jQuery mobile and Snecha javascript frameworks.


It includes stylesheets customized for each device to give the applications a native look and feel. These stylesheets are included by default in all generated Rhodes applications (public/css/), and are included in the application layout file (app/layout.erb).





Application Configuration


Build time configuration is specified in the“build.yml”file. It is used to setup configuration related toplatforms and app version, targeted OS version, production configuration, and device capabilities like camera, vibrate, bluetooth, etc.


Build time configuration is specified in“rhoconfig.txt”file. It is used to specify various applicationsettings like what should be the first screen of the application, how to go to settings page, whether the app should run in a full screen mode, what should be the startup animation, etc.


Rake Tasks


Similar to Rails, Rhodes also provides various rake tasks specific to platform for building development and production packages for the application, debugging and running the application. Here are some examples:


rake run:android


rake run:android:device


rake uninstall:android:device


rake device:android:production



Web Services


Rhodes provides tight integration with RhoSync service for interacting with Web Services/Backend applications. However, it also provides another simpler utility called AsyncHttp. It can be used to interact with the backend applications built with Rails or any other technology to fetch and post data.


Here’s an example:


def async_show Rho::AsyncHttp.get(


:url => "{@params["product_id"]}.json", :callback => url_for(:action => :show_callback)



@response["headers"]["Wait-Page"] = "true" render :action => :waiting




Hope that this article provided a good brief on how to get started with building mobile apps and now you shouldn’t have any excuse for not trying out the mobile apps ;). If you are looking for a simpler alternative, then  PhoneGap is a good option, it doesn’t provide as much features as Rhomobile does, but it’s catching up fast.


Get more information on: Mobile Applications Development

For more information visit: Mobile Web Applications

Add A Comment: