Rails “table-less” Model

孤人 提交于 2019-12-12 10:17:03

问题


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.

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.


回答1:


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

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/



来源:https://stackoverflow.com/questions/19250863/rails-table-less-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!