@@ -50,8 +50,6 @@ Resources must be derived from `JSONAPI::Resource`, or a class that is itself de
5050For example:
5151
5252``` ruby
53- require ' jsonapi/resource'
54-
5553class ContactResource < JSONAPI ::Resource
5654end
5755```
@@ -64,8 +62,6 @@ the `attribute` method, and multiple attributes can be declared with the `attrib
6462For example:
6563
6664``` ruby
67- require ' jsonapi/resource'
68-
6965class ContactResource < JSONAPI ::Resource
7066 attribute :name_first
7167 attributes :name_last , :email , :twitter
@@ -81,8 +77,6 @@ This allows a resource's methods to access the underlying model.
8177For example, a computed attribute for ` full_name ` could be defined as such:
8278
8379``` ruby
84- require ' jsonapi/resource'
85-
8680class ContactResource < JSONAPI ::Resource
8781 attributes :name_first , :name_last , :email , :twitter
8882 attribute :full_name
@@ -127,8 +121,6 @@ the `update` or `create` methods, override the `self.updatable_fields` and `self
127121This example prevents ` full_name ` from being set:
128122
129123``` ruby
130- require ' jsonapi/resource'
131-
132124class ContactResource < JSONAPI ::Resource
133125 attributes :name_first , :name_last , :full_name
134126
@@ -280,8 +272,6 @@ declared using the `filter` method, and multiple filters can be declared with th
280272For example:
281273
282274``` ruby
283- require ' jsonapi/resource'
284-
285275class ContactResource < JSONAPI ::Resource
286276 attributes :name_first , :name_last , :email , :twitter
287277
@@ -290,6 +280,25 @@ class ContactResource < JSONAPI::Resource
290280end
291281```
292282
283+ ##### Default Filters
284+
285+ A default filter may be defined for a resource using the ` default ` option on the ` filter ` method. This default is used
286+ unless the request overrides this value.
287+
288+ For example:
289+
290+ ``` ruby
291+ class CommentResource < JSONAPI ::Resource
292+ attributes :body , :status
293+ has_one :post
294+ has_one :author
295+
296+ filter :status , default: ' published,pending'
297+ end
298+ ```
299+
300+ The default value is used as if it came from the request.
301+
293302##### Finders
294303
295304Basic finding by filters is supported by resources. This is implemented in the ` find ` and ` find_by_key ` finder methods.
@@ -729,13 +738,14 @@ module JSONAPI
729738 KEY_NOT_INCLUDED_IN_URL = 110
730739 INVALID_INCLUDE = 112
731740 RELATION_EXISTS = 113
732- INVALID_SORT_PARAM = 114
741+ INVALID_SORT_CRITERIA = 114
733742 INVALID_LINKS_OBJECT = 115
734743 TYPE_MISMATCH = 116
735744 INVALID_PAGE_OBJECT = 117
736745 INVALID_PAGE_VALUE = 118
737746 INVALID_FIELD_FORMAT = 119
738747 INVALID_FILTERS_SYNTAX = 120
748+ SAVE_FAILED = 121
739749 FORBIDDEN = 403
740750 RECORD_NOT_FOUND = 404
741751 UNSUPPORTED_MEDIA_TYPE = 415
@@ -761,7 +771,6 @@ The `ResourceSerializer` can be used to serialize a resource into JSON API compl
761771 method that takes a resource instance or array of resource instances to serialize. For example:
762772
763773``` ruby
764- require ' jsonapi/resource_serializer'
765774post = Post .find(1 )
766775JSONAPI ::ResourceSerializer .new (PostResource ).serialize_to_hash(PostResource .new (post))
767776```
0 commit comments