@@ -37,7 +37,7 @@ Or install it yourself as:
3737
3838Back to example above, all you have to do is to mark ` Product ` as ` actable ` and all product type models as ` acts_as :product ` :
3939
40- ``` Ruby
40+ ``` ruby
4141class Product < ActiveRecord ::Base
4242 actable
4343 belongs_to :store
6767and add foreign key and type columns to products table as in a polymorphic relation.
6868You may prefer using a migration:
6969
70- ``` Ruby
70+ ``` ruby
7171change_table :products do |t |
7272 t.integer :actable_id
7373 t.string :actable_type
7676
7777or use shortcut ` actable `
7878
79- ``` Ruby
79+ ``` ruby
8080change_table :products do |t |
8181 t.actable
8282end
@@ -90,7 +90,7 @@ on parent table and they will be touched after submodel updates (You can use the
9090Now ` Pen ` and ` Book ` ** acts as** ` Product ` , i.e. they inherit ` Product ` s ** attributes** ,
9191** methods** and ** validations** . Now you can do things like these:
9292
93- ``` Ruby
93+ ``` ruby
9494Pen .create name: ' Penie!' , price: 0.8 , color: ' red'
9595 # => #<Pen id: 1, color: "red">
9696Pen .where price: 0.8
@@ -119,14 +119,14 @@ Pen.first.info
119119
120120On the other hand you can always access a specific object from its parent by calling ` specific ` method on it:
121121
122- ``` Ruby
122+ ``` ruby
123123Product .first.specific
124124 # => #<Pen ...>
125125```
126126
127127If you have to come back to the parent object from the specific, the ` acting_as ` returns the parent element:
128128
129- ``` Ruby
129+ ``` ruby
130130Pen .first.acting_as
131131 # => #<Product ...>
132132```
@@ -139,7 +139,7 @@ Pen.where(...).actables
139139
140140In ` has_many ` case you can use subclasses:
141141
142- ``` Ruby
142+ ``` ruby
143143store = Store .create
144144store.products << Pen .create
145145store.products.first
@@ -148,7 +148,7 @@ store.products.first
148148
149149You can give a name to all methods in ` :as ` option:
150150
151- ``` Ruby
151+ ``` ruby
152152class Product < ActiveRecord ::Base
153153 actable as: :producible
154154end
@@ -169,7 +169,7 @@ Make sure you know what you are doing when overwriting `validate` or `autosave`
169169
170170You can pass scope to ` acts_as ` as in ` has_one ` :
171171
172- ``` Ruby
172+ ``` ruby
173173acts_as :person , -> { includes(:friends ) }
174174```
175175
@@ -182,7 +182,7 @@ Make sure you know what you are doing when overwriting `polymorphic` option.
182182
183183If your ` actable ` and ` acts_as ` models are namespaced, you need to configure them like this:
184184
185- ``` Ruby
185+ ``` ruby
186186class MyApp ::Product < ApplicationRecord
187187 actable inverse_of: :product
188188end
@@ -201,7 +201,7 @@ To use this library custom RSpec matchers, you must require the `rspec/acts_as_m
201201
202202Examples:
203203
204- ``` Ruby
204+ ``` ruby
205205require " active_record/acts_as/matchers"
206206
207207RSpec .describe " Pen acts like a Product" do
0 commit comments