问题
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