Search code examples
ruby-on-railsrestaccounting

Ruby on Rails REST design question - transfer money between accounts


I have an Account class, want to implement transfer screens to allow a user to transfer money between 2 accounts.

How would I implement this ins RESTfull way?

I have the standard account and rest actions for that, thats fine. But how would I implement transfer?

Normally I would just add a method called "transfer" (called to render the screen) and "transfer_update"(called on submit) to the accounts controller and corresponding views, but I don think this is very RESTfull.

thanks Joel


Solution

  • You mention your Account class, but not the class that represents postings or journals. See http://homepages.tcp.co.uk/~m-wigley/gc_wp_ded.html (Archived).

    Using the language of the referenced site, the "resource" that's being created for a transfer is a journal (entry), consisting of two postings, each to different accounts. So you would want a JournalsController. To add a transfer you would POST to the index action of the JournalsController. Parameters would include date, amount, debit_account, credit_account, payee, memo, etc.

    Using REST on AccountsController would be for creating, updating, or deleting accounts, not postings (transactions) which are contained by accounts.