I have a rails model where some part of data comes from database and other by calling a restful web service. Is there a way to use both ActiveRecord and ActiveResource in the same model to achieve this?
Ideally I would like to load the attributes that it gets from web service lazily (when accessed in controller) and only load the db attributes by default. Is it best if I create two models one th开发者_如何转开发at accesses service using ActiveResource and one with ActiveResource which :has_one
of the active resource model. Also, how to make sure I only call the service when only activeresource methods are accessed (like a before_filter but for only those methods - if I have a relationship with other model, doesn't rails already do that)?
Thanks in advance.
Have a look at the delegate
method... This way you can proxy methods to another model.
http://blog.wyeworks.com/2009/6/4/rails-delegate-method
精彩评论