The Model View Controller pattern separates data definitions (models) from business logic (controllers) from interfaces (views). MVC based apps are far more maintainable and understandable. All modern web development languages now use MVC as their dominant approach (Java/Struts, ASP.NET MVC, Python/Django, Ruby/Rails, PHP/Zend).
By convention, files for each Model include a controller, a model class and view templates described below.
To store data locally RhoMobile uses Sqlite on iPhone, Android, and Windows Mobile.On Blackberry version up to 5.0 Rhodes uses Hsql. On version 5.0 and higher it is possible to use Sqlite or Hsql. To access and manipulate stored data you may use RhoMobile’s ORM or OrmModel APIs. ORM stands for object relational mapper and it provides a high level way to make the local database easier to program to.
By convention, your model class is located in the model’s folder. For the model “UserBase” the file would be called “user_base.rb”
Example of added upper_name method to the model:
class UserBase include Rhom::PropertyBag #add model specific code here def upper_name self.name.upcase end end
See more details about Data Models here.
Each controller action usually associated with a View template. The .erb files mentioned above are the templates used for views. Rhodes follows the Rails convention for template naming.
Each generated model controller has several actions to perform basic CRUD (create, read, update and delete) on the object. These actions are:
Developer’s may also create any number of controller actions by simply defining new methods in the controller class. Each action associated with a url and can be performed by calling that url from the View in the WebView control. WebView control is a Web Browser imbedded in the application UI.
For example, if you have an Account Model your controller actions will be in account_controller.rb file. To defined an action called ‘list’ you would create a method ‘list’ in the account_controller.rb file:
def list #implement required business logic here #... #return result to the browser render :action => :list end
To access this method from a view, you would specify the url to be ‘Account/list’ url.