The difference between an active model, an active record, and an active resource

Is there anyone who can help me out by defining the exact difference between Active Model, Active Record and Active Resource. I did enough googling to find the exact difference, but did not get anything specific that could determine the exact difference between them. Right now they all look the same to me. So please give me an appropriate answer with some specific points.

+42
ruby-on-rails-3 rails-activerecord activeresource activemodel
Sep 29 '12 at 13:56
source share
3 answers

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 parts related to the model that did not have the Rails 2 ActiveRecord database requirements and were ported to ActiveModel. So ActiveModel includes things like validation. Additional 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 the class with the database. This will provide class functionality, such as methods that make it easy to retrieve records from the database (for example, the search method).

ActiveResource : similar to ActiveRecord. However, instead of supporting the database, the ActiveResource object is supported by another application through the web service API. Additional information: http://ofps.oreilly.com/titles/9780596521424/activeresource_id59243.html

(Failed to find out about ActiveBase ... where did you hear it from?)

+64
Oct 07
source share
— -

What I understand:

ActiveModel + Database Support = ActiveRecord

ActiveModel via WebService = AcitveResource API

+8
Dec 13 '13 at 11:02
source share

ActiveModel https://github.com/rails/rails/tree/master/activemodel

Think of a super model that constantly needs to be tested.

ActiveModel can be used for many things, but is mostly recognized for adding validation support to / db model records.




ActiveRecord https://github.com/rails/rails/tree/master/activerecord

Think of a record as in a table record.

Establishes a mapping between the new class and the existing table in the database.

In the context of an application, these classes are commonly called models. Models can also be connected to other models; this is done by defining associations.

class Firm < ActiveRecord::Base has_many :clients has_one :account belongs_to :conglomerate end 

In the background, rails use ActiveRecord to control the circuit and determine the properties for your records, acting as ORM (relational object mapping):

" ORM: An object that wraps a row in a table or database view encapsulates access to the database and adds domain logic to this data."

The diagram describes the recording properties.




ActiveResource https://github.com/rails/activeresource

Think of a resource as R in the URL or resource routing which involves many rails.

Allows you to do things like C , R etrieve, U pdate, or D estroy (CRUD) via HTTP.

  tyler = Person.find(1) 

When a request is routed to a resource route, a RESTful request matches its corresponding HTTP verbs and their interactions with databases

  GET => Person.find(1) POST => Person.new(:name => 'Tyler', :favorite_page => 'stackoverflow') PUT => tyler.save DELETE => tyler.destroy 
+5
10 Oct '14 at 1:30
source share



All Articles