Note: This is based on this example, which is based on an example that Dima and I built together. Both of us use this example everywhere, and the original origin of the data model is my Flexible Rails book. (No, Flexible Rails doesn’t cover RestfulX; what I mean is that this model.yml is creating an app that strongly resembles the example app in Flexible Rails.)
0. If you have run this before, delete a pomodo.db database from home directory.
1. Create the Rails app, install RestfulX and create the Flex project:
$ sudo gem install restfulx
$ rails -d mysql pomodo
$ cd pomodo
2. Edit config/environment.rb and add:
config.gem "restfulx"
3. Run rx_config with the distributed option:
$ ./script/generate rx_config --distributed
4. Create your data model:
$ emacs db/model.yml
project:
- name: string
- notes: text
- start_date: date
- end_date: date
- completed: boolean
- belongs_to: [user]
- has_many: [tasks]
location:
- name: string
- notes: text
- belongs_to: [user]
- has_many: [tasks]
task:
- name: string
- notes: text
- start_time: datetime
- end_time: datetime
- completed: boolean
- next_action: boolean
- belongs_to: [project, location, user]
note:
- content: text
- belongs_to: [user]
user:
- login: string
- first_name: string
- last_name: string
- email: string
- has_many: [tasks, projects, locations]
- has_one: [note]
5. Generate the app, recreate the database and run your server:
$ ./script/generate rx_yaml_scaffold
$ rake db:refresh
$ ./script/server
6. Import the project into Flex Builder, compile the Flex code and go to http://localhost:3000.
7. Convert the app to AIR:
a) Stop your server.
b) Delete the project in Flex Builder. (Don’t delete contents.)
c) ./script/generate rx_config -a –distributed
d) Import the pomodo project into Flex Builder again.
e) [WORKAROUND] Fix the routes, which got hosed by rx_config -a –distributed:
map.resources :locations
map.resources :notes
map.resources :tasks
map.resources :projects
map.resources :users
8. Test online/offline:
a) Start your server.
b) Rebuild and run the AIR app. Note that it’s empty.
c) Start your server. Note that online detection works. Do a pull.
d) Create tasks, projects, etc.
e) Do a push.