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?
I think you are looking for something like ActiveResource
For Rails 4 checkout this:
https://github.com/whichdigital/active-rest-client
This gem is for accessing REST services in an ActiveRecord style. ActiveResource already exists for this, but it doesn't work where the resource naming doesn't follow Rails conventions, it doesn't have in-built caching and it's not as flexible in general.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With