Ruby on Rails REST design question - transferring money between accounts

I have an Account class, you want to implement transfer screens to allow the user to transfer money between two accounts.

How do I implement this RESTfull method?

I have standard actions for the account and rest for this, this is normal. But how can I implement the transfer?

Usually, I simply add a method called “transfer” (called to display the screen) and “transfer_update” (called to send) to the account controller and corresponding views, but I don’t think it is very RESTfull.

thanks Joel

+3
source share
3

Account, , . . http://homepages.tcp.co.uk/~m-wigley/gc_wp_ded.html ().

, "", , (), , . JournalsController. , POST JournalsController. , , debit_account, credit_account, payee, memo ..

REST AccountsController , , (), .

+3

.

POST /transfers HTTP/1.1
Host: restful.bank.com
Content-Type: application/json; charset=utf-8
Accept: application/json

{ "transfer": {
  "source_account_id": "9d2d894c242f391a",
  "destination_account_id": "83ac039d8302abd5"
  "amount": "$200.00"
} }

.

HTTP/1.1 201 Created
Date: #{right-now}
Content-Type: application/json; charset=utf-8
Location: https://restful.bank.com/transfers/938ac39cb5ddccfa

{ "transfer": {
  "id": "938ac39cb5ddccfa",
  "href": "https://restful.bank.com/transfers/938ac39cb5ddccfa",
  "source_account_id": "9d2d894c242f391a",
  "destination_account_id": "83ac039d8302abd5"
  "amount": "$200.00"
} }
+3

The RESTful Web Services book has a good example of how to approach this exact problem, and which is better, an example in Rails :)

If you can't check it from the library, what the hell, just buy a thing. It is not so expensive and has a lot of useful information on how to implement REST and ROA.

+1
source

All Articles