Development Architecture
Rhodes applications are installed and run as native applications. However, you develop using the web development paradigm. You define the user interface of your application in HTML and CSS. Then, at runtime, the HTML and CSS is rendered in a native browser UI control that is embedded in your application by the Rhodes framework. JavaScript may be used for some interaction control the same way that you would use JavaScript in a web application.
You can also add application logic to your views using embedded Ruby (ERB), as you would in a Ruby on Rails application. ERB files are similar to PHP or JSP, where code can be mixed with markup to create dynamic HTML. Rhodes will generate the complete HTML, evaluating the Ruby code before the HTML is rendered by the browser UI Control, which will then dynamically execute any JavaScript that is on the page.
You also write Ruby code for the application logic that implements the flow of control for your application. Rhodes follows the Model-View-Controller (MVC) pattern that is similar to Ruby on Rails and other web frameworks. You implement methods in your controller to define actions that map to HTTP requests. Your controller action will typically fetch data from your model (implemented in the Rhodes ORM layer, Rhom) and render a view (implemented as HTML ERB).
In Figure 6-1 you can see the MVC pattern illustrated with the Rhodes object model and an example use case. In the example, there is a "New Product" page where the user can fill in the form field to provide values for the new product attributes. When the user clicks the Create button, a request is made to a lightweight embedded web server in Rhodes that only exists to respond to these UI request and RhoController actions. When a user clicks on a URL in the HTML view, a controller action is called. In this example, the ProductController create method is called. The controller action then calls the Product model, implemented with Rhom to save a new product in the local database. Then a view is rendered to display the result to the user. The entire web response cycle happens locally on the device.
- Figure 6-1. The MVC Model
Post a comment