On Tuesday, September 25, 2012 1:08:46 AM UTC-7, Zhongjie Wu wrote:
Hi, I am writing a management system and one of the datasource is external(read-only) and I need to use REST API to access them. Can I just reuse the Model part of MVC but override those database access methods to do REST calls instead?
Absolutely. The objects in your model don't have to inherit from ActiveRecord or any other part of Rails if you don't need them to. Just write up an object to wrap the API calls.
Rails used to have a module called ActiveResource for this, but it seems nobody liked it enough to keep it working, so it was dropped. In my current project, I just have to read from the REST API, and
https://github.com/archiloque/rest-client is working well so far.
-David