Yeti Media

RSS
Nov 7

ActiveResource is dead, long live ActiveResource

by Guillermo Iguaran:

As many of you already know, ActiveResource was removed from the Rails master branch and won’t be shipped with Rails 4. The motivation behind the removal was the lack of maintenance and maintainers on Core Team. But its not all bad news, ActiveResource now lives as an independent plugin and is receiving more love from contributors. There is also a small team lead by Jeremy Kemper working on it. Since the extraction from Rails we have added some nice features:

  • Basic support for associations: has_many, has_one, belongs_to now can be used in ActiveResource models. Here is a small example of it:

https://gist.github.com/4035394

https://gist.github.com/4035401

If the request to http://37s.sunrise.i:3000/posts/1 returns comments then @post.comments will be available immediately, if not, it will be populated the first time that @post.comments is called with a request to http://37s.sunrise.i:3000/posts/1/comments

  • Basic support for callbacks, after_create, after_save, after_update, before_create, before_save, before_update, before_validation, after_validation and other friends that can be used with ActiveResource models. A simple example:

https://gist.github.com/4035404

  • Support for APIs without a format in the path, you can now consume APIs that support setting of the desired format through the Accept header. I think this will be a nice feature appreciated by you RESTafarians ;)

  • Support for non-RESTful APIs, the ActiveResource models can set a collection_parser which can deal with API responses that do not match Rails (RESTful) conventions, a handy example to understand how it works:

https://gist.github.com/4035407

  • Support for Singleton resources through the ActiveResource::Singleton mixin. An example:

https://gist.github.com/4035417

  • Fixes, fixes and more fixes, we have merged a lot of fixes provided by contributors

We will release ActiveResource 4.0 in the next months (trying to be in sync with Rails 4 release) but I will be working soon in a plugin to backport all these changes to ActiveResource 3.2, then you won’t need to wait more to use all these exciting features in your current projects. Long live to ActiveResource!!!.

We will keep you posted with more updates about Rails 4 and all their related projects.

About Guillermo Iguaran:

Senior Software Architect and Open-source evangelist with more than 4 years of experience working as a software developer and programming with Ruby. Guillermo is a young developer and open source enthusiast who is rapidly moving up the ranks in the ruby community. Currently, he is a Rails Core Contributor and has contributed to some popular projects of the ruby world like Rubinius and JRuby.