Rails“无表"模型 [英] Rails "table-less" Model

查看:44
本文介绍了Rails“无表"模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我专注于将我的逻辑转移到我的模型中.我已经将 Stripe Payments 集成到我的 Rails 4 应用程序中,并且在我的标准(表支持)模型之一中处理了与 Stripe 的 API 的交互.

I'm focused on moving my logic into my models. I've already integrated Stripe Payments into my Rails 4 app and the interaction with Stripe's API is taken care of in one of my standard (table-backed) models.

然而,我刚刚开始考虑是否应该为这种场景引入无表模型(可能是 stripe.rb)来处理 API 调用,创建新的 Stripe 客户、更新卡片等

However, I'm just beginning to think about whether I should introduce a table-less model for this scenario (perhaps stripe.rb) to take care of the API calls, create new Stripe customers, updates cards etc.

任何人对此有任何建议,如果您推荐新模型,您能否强调一些我需要注意的关于无表模型的领域.

Anyone got any advice on this and if you recommend a new model could you highlight some areas that I will need to be aware of regarding table-less models.

推荐答案

您可以将 api 的逻辑提取到服务对象中.

You could extract the logic for the api into a service object.

很简单.只需在您的应用程序目录中创建一个服务文件夹,您放置在其中的任何 *.rb 文件都会在 Rails 4 中默认自动加载.

It's pretty simple. Just create a services folder in you app directory, any *.rb files you place in there will be autoloaded by default in rails 4.

查看以下文章以获得更多想法

checkout the following article for more ideas

http:///blog.codeclimate.com/blog/2012/10/17/7-ways-to-decompose-fat-activerecord-models/

这篇关于Rails“无表"模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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