Ruby on Rails REST 设计问题 - 账户之间转账
我有一个 Account 类,想要实现转账屏幕以允许用户在 2 个账户之间转账。
我将如何以 RESTfull 方式实现这个?
我有标准帐户和休息操作,那很好。但我该如何实现转移呢?
通常我只会向帐户控制器和相应的视图添加一个名为“transfer”(调用以渲染屏幕)和“transfer_update”(在提交时调用)的方法,但我认为这非常 RESTfull。
谢谢 乔尔
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您提到了您的帐户类别,但没有提到代表帖子或日记的类别。请参阅http://homepages.tcp.co.uk/~m-wigley/ gc_wp_ded.html(已存档)。
使用引用站点的语言,为传输创建的“资源”是一个日记帐(条目),由两个过帐组成,每个过帐到不同的帐户。所以你需要一个 JournalsController。要添加传输,您需要 POST 到 JournalsController 的索引操作。参数将包括日期、金额、借记帐户、贷记帐户、收款人、备忘录等。
在 AccountsController 上使用 REST 将用于创建、更新或删除帐户,而不是帐户包含的过帐(交易)。
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.
执行传输的安静请求的示例。
相应的回应。
An example of a restful request to perform a transfer.
Corresponding response.
RESTful Web Services 一书有一个很好的示例,说明如何解决这个确切的问题,更好的是,该示例在 Rails 中:)
如果你无法从图书馆借出它,那又怎么样,就买这个东西吧。它并没有那么昂贵,并且包含许多有关如何实施 REST 和 ROA 的有用信息。
The book RESTful Web Services has a good example of how to approach this exact problem, and what's better, the example is in Rails :)
If you can't check it out from a library, what the heck, just buy the thing. It's not that expensive and it has lots of useful information about how to implement REST and ROA.