Code examples for a Dojo Mobile one page application. Backend in Ruby/Sinatra
I wrote a few days ago that I am excited about how easy it is to make simple one page web apps using Dojo Mobile that look good and work fine on portable devices (Android and iOS) and regular web browsers. I don't do a lot of UI development for my work but when I do write web apps it is great to also be able to support mobile devices with a small amount of additional simple code. In this post I will show you hopefully useful code snippets for cookingspace.com that may save you some time if you want to write the same type of apps.
Last weekend I decided that I wanted a new mobile web interface to my old Cooking Space web site. I wanted to be able to quickly look up a recipe on my cellphone, see the ingredient list, and be able to specify how many people need to be served. I also want to see the nutrition data for the recipe. A top level requirement is that once the web page renders then everything is updated with AJAX. There are only two user interactions:
- Enter a few search terms to locate recipes and show them in a format compatible with both small devices and a web browser on a laptop.
- A control for changing the number of people a recipe will serve - this adjusts the amounts in the ingredients list using AJAX.
The Sinatra controller code is very simple since it only has to serve up the web page and then handle AJAX calls using the model code. I reformatted the Ruby code to make it a little more verbose and easier to understand:
This is a simple example and hopefully will give you a good start creating one page mobile HTML5 web apps using Dojo Mobile.