Weve had a little Expenses Rails app for tracking charges and funneling them back to Accounting. One of the key bits is that we can upload a picture of the receipt to each expense. Its remarkable how good resolution camera phones have these days, and its a lot better then walking around with a pocketful of receipts while on a business trip!
So we used the basic Rails scaffolding, but I am a big fan of Richard Whites Ajax Scaffold. And since it is now a Rails Plugin, I wanted to give it a try. I dropped it into the app, and everything worked fine. That is until I tried to upload my image of a receipt. Bam… I started thinking this was a weakness of Ajax Scaffold, but after a bit of digging around it turns out binary data cant be sent via AJAX calls! Ugh…
Well, after playing around with various options for a while, i decided that I wasnt going to use something weird like a Flash based uploader or what not. Instead, when adding a new expense, I do a regular post via form_tag
that takes you back to the list page, and when editing a receipt, where image changing isnt supported anyway, I use the ajax goodness via form_remote_tag
.
I can tell which method is being invoked on _new_edit.rhtml
partial by doing:
, and use the appropriate form tag. The only issue was that to keep the other Ajax calls working properly, the form_tag
id had to use the full :id => element_form_id(@options)
id. The only real downside is that when creating a new expense, if there is an error, you are popped out of the table view, into a page with just the new expense partial, but you can still save your data.
At any rate, Ajax Scaffold as plugin has grown more mature then ever. I really appreciate how easy it is to do things like change sorting order, or add your own filters to the data. And the fact that all the raw Ajax Scaffold template stuff stays in /views/ajax_scaffold/
, and allows you to override individual .rthtml templates by adding them to your /views/model/
directory is just great. It also become a lot cleaner and easier to understand the internal workings as well. I am very much looking forward to Ajax Scaffold 4.0!