ruby-on-rails-3rails-activerecordactivemodelactiveresource

Difference between Active Model, Active Record and Active Resource


Is there anyone who can help me by defining the exact difference between Active Model, Active Record and Active Resource. I have done enough googling in order to find the exact difference, but didn't get anything concrete which can tell the exact difference between them. Right now they all look same to me. So please give me the appropriate answer with some concrete points.


Solution

  • Rails 3 is designed with modularity in mind. Each module has its own purpose and functionality.

    ActiveModel: This component was created in Rails 3. They took all the model related parts that did not have a database requirement of Rails 2 ActiveRecord and moved it into ActiveModel. So ActiveModel includes things like validations. More information: http://www.rubyinside.com/rails-3-0s-activemodel-how-to-give-ruby-classes-some-activerecord-magic-2937.html

    ActiveRecord: This is the component that associates a class to the database. This will give the class functionality such as methods that make it easy to pull records from the database (An example is the find method).

    ActiveResource: Similar to ActiveRecord. However, instead of being backed by a database, an ActiveResource object is backed by another application through a web service API. More information: http://ofps.oreilly.com/titles/9780596521424/activeresource_id59243.html

    (Couldn't figure out about ActiveBase... where did you hear it from?)