You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+23-13Lines changed: 23 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ JSONAPI::Utils (JU) was built on top of [JSONAPI::Resources](https://github.com/
13
13
Add these lines to your application's Gemfile:
14
14
15
15
```ruby
16
-
gem 'jsonapi-utils', '~> 0.4.3'
16
+
gem 'jsonapi-utils', '~> 0.4.4'
17
17
```
18
18
19
19
And then execute:
@@ -22,11 +22,23 @@ And then execute:
22
22
$ bundle
23
23
```
24
24
25
-
## Macros
25
+
## Response Macros
26
26
27
27
### jsonapi_render
28
28
29
-
Validates the request and renders ActiveRecord/Hash objects into JSON API-compliant responses.
29
+
Takes ActiveRecord/Hash objects and generates JSON API-compliant responses.
30
+
31
+
```ruby
32
+
# GET /users
33
+
defindex
34
+
jsonapi_render json:User.all
35
+
end
36
+
37
+
# GET /users/:id
38
+
defshow
39
+
jsonapi_render json:User.find(params[:id])
40
+
end
41
+
```
30
42
31
43
Arguments:
32
44
@@ -37,13 +49,9 @@ Arguments:
37
49
-`count`: explicitly points the total count of records for the request in order to build a proper pagination. By default, JU will count the total number of records.
38
50
-`model`: sets the model reference in cases when `json` is a Hash or a collection of Hashes.
In the backstage that's the method that actually parsers ActiveRecord/Hash objects and builds a new Hash compliant with JSON API. It can be called anywhere in controllers, concerns etc.
73
+
In the backstage this is the method that actually parses ActiveRecord/Hash objects and builds a new Hash compliant with JSON API. It can be called anywhere in your controllers being very useful whenever you need to work with a JSON API "serialized" version of your object before rendering it.
66
74
67
75
```ruby
68
-
collection = jsonapi_serialize(User.all)
69
-
render json: do_some_magic_with(collection)
76
+
defindex
77
+
result = do_some_magic(jsonapi_serialize(User.all))
78
+
render json: result
79
+
end
70
80
```
71
81
72
82
Arguments:
73
-
- It receives a second optional argument with the same options for`jsonapi_render`.
83
+
- It receives the same options as`jsonapi_render`.
0 commit comments