Rails Model to use API instead of Database

Greg Olsen picture Greg Olsen · Aug 24, 2012 · Viewed 8.1k times · Source

I'm refactoring a rails app that currently uses a database and ActiveRecord so that instead of of the database, it uses a JSON API (Sinatra).

What would be the best way to refactor the models? The API will return all the same information as the database used to. Infact it IS the same database, but for scalability and multiple apps requiring access to the data, we needed to turn it into an API. Ideally only the Models will need to change and ideally I can keep some validation in the rails app.

How can I change the models so they retrieve and save their instances via API calls rather than ActiveRecord database calls?

Answer

Dom Barker picture Dom Barker · Sep 19, 2013

I think you are looking for something like ActiveResource