Ruby on Rails REST设计问题-在帐户之间转移资金 [英] Ruby on Rails REST design question - transfer money between accounts

查看:73
本文介绍了Ruby on Rails REST设计问题-在帐户之间转移资金的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Account类,想要实现转帐屏幕,以允许用户在2个帐户之间转帐。

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

我将如何以RESTfull方式实现这种方式?

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?

通常,我只需添加一个名为 transfer(称为渲染屏幕)和 transfer_update(提交时称为)的方法即可。帐户控制器和相应的视图,但是我不认为这非常RESTful。

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.

感谢
Joel

thanks Joel

推荐答案

您提到的是Account类,但没有提到代表过帐或日记帐的类。参见 http://homepages.tcp.co.uk/~m-wigley/ gc_wp_ded.html 已存档)。

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).

使用引用站点的语言,为传输创建的资源是日记(条目) ,由两个发布组成,每个发布到不同的帐户。因此,您需要一个JournalsController。要添加传输,您需要对JournalsController的index操作进行POST。参数将包括日期,金额,借方帐户,贷方帐户,收款人,备忘录等。

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.

在AccountsController上使用REST用于创建,更新或删除帐户,而不是过帐(交易))。

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

这篇关于Ruby on Rails REST设计问题-在帐户之间转移资金的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆