Skip to content

Commit dc45cea

Browse files
committed
chore
1 parent 46a3294 commit dc45cea

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

comparison_with_activemodel_and_activetype.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ You can make your "BaseFormObject":
88
class BaseFormObject
99
# Acts as Active Model
1010
# includes Rails integration and Validation
11-
include ActiveModel::Base
12-
13-
# Enable Attribute API
11+
include ActiveModel::Model
12+
13+
# Enable Attribute API
1414
# <https://api.rubyonrails.org/classes/ActiveRecord/Attributes/ClassMethods.html#method-i-attribute>
1515
# <https://bigbinary.com/blog/rails-5-attributes-api>
1616
include ActiveModel::Attributes
17-
17+
1818
# (Optional) Enable dirty tracking
1919
# <https://api.rubyonrails.org/classes/ActiveModel/Dirty.html>
2020
include ActiveModel::Dirty
21-
21+
2222
# (Optional) Enable serialization
2323
# e.g. dump attributes to hash or JSON
2424
include ActiveModel::Serialization
@@ -31,7 +31,7 @@ Usage:
3131
class Book < BaseFormObject
3232
attribute :title, :string
3333
attribute :score, :integer
34-
34+
3535
validates :title, presence: true
3636
validates :score, numericality: { only_integer: true }
3737
end
@@ -81,7 +81,7 @@ you can just define a `class` to do that.
8181
```ruby
8282
class Post
8383
attr_reader :title, :body
84-
84+
8585
# Initializer, attribute writers, methods, etc.
8686
end
8787
```
@@ -92,7 +92,7 @@ But we're on Rails, compared to Active Record model, it's lacking:
9292
- Validation
9393
- Integrate with Rails, the most part is integrate with Strong parameter, form helpers and I18n
9494

95-
### ActiveModel::Base
95+
### ActiveModel::Model
9696

9797
Since Rails 4, Active Record has extracted the Rails integration layer called Active Model, it defined essential interfaces that how controller and view helpers can interact with the model.
9898

@@ -104,7 +104,7 @@ I recommend read it first, here I want to explain what features contains in `Act
104104
module Model
105105
# It's a Mixin
106106
extend ActiveSupport::Concern
107-
107+
108108
# Provides `write_attribute`, `read_attribute` and `assign_attributes` methods as unify attribute accessor,
109109
# other extensions will depend on this
110110
include ActiveModel::AttributeAssignment

0 commit comments

Comments
 (0)