@@ -21,23 +21,29 @@ backed by ActiveRecord models or by custom objects.
2121* [ Usage] (#usage)
2222 * [ Resources] (#resources)
2323 * [ JSONAPI::Resource] (#jsonapiresource)
24+ * [ Context] (#context)
2425 * [ Attributes] (#attributes)
2526 * [ Primary Key] (#primary-key)
2627 * [ Model Name] (#model-name)
28+ * [ Model Hints] (#model-hints)
2729 * [ Relationships] (#relationships)
2830 * [ Filters] (#filters)
2931 * [ Pagination] (#pagination)
3032 * [ Included relationships (side-loading resources)] (#included-relationships-side-loading-resources)
3133 * [ Resource meta] (#resource-meta)
32- * [ Custom Links] (#resource-meta )
34+ * [ Custom Links] (#custom-links )
3335 * [ Callbacks] (#callbacks)
3436 * [ Controllers] (#controllers)
3537 * [ Namespaces] (#namespaces)
3638 * [ Error Codes] (#error-codes)
3739 * [ Handling Exceptions] (#handling-exceptions)
3840 * [ Action Callbacks] (#action-callbacks)
3941 * [ Serializer] (#serializer)
42+ * [ Serializer options] (#serializer-options)
43+ * [ Formatting] (#formatting)
44+ * [ Key Format] (#key-format)
4045 * [ Routing] (#routing)
46+ * [ Nested Routes] (#nested-routes)
4147* [ Configuration] (#configuration)
4248* [ Contributing] (#contributing)
4349* [ License] (#license)
@@ -155,6 +161,28 @@ In the above example vehicles are immutable. A call to `/vehicles` or `/vehicles
155161of either ` car ` or ` boat ` . But calls to PUT or POST a ` car ` must be made to ` /cars ` . The rails models backing the above
156162code use Single Table Inheritance.
157163
164+ #### Context
165+
166+ Sometimes you will want to access things such as the current logged in user (and other state only available within your controllers) from within your resource classes. To make this state available to a resource class you need to put it into the context hash - this can be done via a ` context ` method on one of your controllers or across all controllers using ApplicationController.
167+
168+ For example:
169+
170+ ``` ruby
171+ class ApplicationController < JSONAPI ::ResourceController
172+ def context
173+ {current_user: current_user}
174+ end
175+ end
176+
177+ # Specific resource controllers derive from ApplicationController
178+ # and share its context
179+ class PeopleController < ApplicationController
180+
181+ end
182+ ```
183+
184+ You can put things that affect serialization and resource configuration into the context.
185+
158186#### Attributes
159187
160188Any of a resource's attributes that are accessible must be explicitly declared. Single attributes can be declared using
@@ -956,7 +984,7 @@ class CityCouncilMeeting < JSONAPI::Resource
956984 attribute :title , :location , :approved
957985
958986 def custom_links (options )
959- { minutes: options[:serialzer ].link_builder.self_link(self ) + " /minutes" }
987+ { minutes: options[:serializer ].link_builder.self_link(self ) + " /minutes" }
960988 end
961989end
962990```
@@ -991,7 +1019,7 @@ class CityCouncilMeeting < JSONAPI::Resource
9911019 def custom_links (options )
9921020 extra_links = {}
9931021 if approved?
994- extra_links[:minutes ] = options[:serialzer ].link_builder.self_link(self ) + " /minutes"
1022+ extra_links[:minutes ] = options[:serializer ].link_builder.self_link(self ) + " /minutes"
9951023 end
9961024 extra_links
9971025 end
@@ -1135,26 +1163,6 @@ A jsonapi-controller generator is avaliable
11351163rails generate jsonapi:controller contact
11361164```
11371165
1138- ###### Context
1139-
1140- The context that' s used for serialization and resource configuration is set by the controller' s `context` method.
1141-
1142- For example:
1143-
1144- ```ruby
1145- class ApplicationController < JSONAPI::ResourceController
1146- def context
1147- {current_user: current_user}
1148- end
1149- end
1150-
1151- # Specific resource controllers derive from ApplicationController
1152- # and share its context
1153- class PeopleController < ApplicationController
1154-
1155- end
1156- ```
1157-
11581166###### Serialization Options
11591167
11601168Additional options can be passed to the serializer using the `serialization_options` method.
@@ -1854,4 +1862,4 @@ end
18541862
18551863# # License
18561864
1857- Copyright 2014 Cerebris Corporation . MIT License (see LICENSE for details).
1865+ Copyright 2014 - 2016 Cerebris Corporation . MIT License (see LICENSE for details).
0 commit comments