11# jsonapi-rails
2- Rails integration for [ jsonapi-rb] ( https ://github.com/ jsonapi-rb/jsonapi-rb ) .
2+ Rails integration for [ jsonapi-rb] ( http ://jsonapi-rb.org ) .
33
44## Status
55
@@ -18,79 +18,9 @@ And then execute:
1818$ bundle
1919```
2020
21- ## Usage
21+ ## Usage and documentation
2222
23- ### Serialization
24-
25- Example:
26- ``` ruby
27- # app/serializable/serializable_user.rb
28- class SerializableUser < JSONAPI ::Serializable ::Resource
29- type ' users'
30-
31- attribute :name
32- attribute :email do
33- " #{ @object .name} @foo.bar"
34- end
35-
36- has_many :posts do
37- link(:related ) { @url_helpers .user_posts(@object ) }
38- meta foo: :bar
39- end
40-
41- has_many :comments do
42- resources do
43- @object .comments.order(:desc )
44- end
45- end
46-
47- has_many :reviews , Foo ::Bar ::SerializableRev
48-
49- link(:self ) { @url_helpers .user_url(@object .id) }
50- meta do
51- { foo: ' bar' }
52- end
53- end
54-
55- # app/controllers/users_controller.rb
56- # ...
57- user = User .find_by(id: id)
58- render jsonapi: user, include: { posts: [:comments ] }, meta: { foo: ' bar' }
59- # ...
60- ```
61-
62- ### Deserialization
63-
64- Example:
65- ``` ruby
66- class PostsController < ActionController ::Base
67- deserializable_resource :post , only: [:create , :update ] do
68- attribute :title
69- attribute :date
70- has_one :author do |rel , id , type |
71- field user_id: id
72- field user_type: type
73- end
74- has_many :comments
75- end
76-
77- def create_params
78- params.require(:user ).permit!
79- end
80-
81- def create
82- create_params[:title ]
83- create_params[:date ]
84- create_params[:comment_ids ]
85- create_params[:comment_types ]
86- create_params[:user_id ]
87- create_params[:user_type ]
88- # ...
89- end
90- end
91-
92-
93- ```
23+ See [ jsonapi-rb.org/guides] ( http://jsonapi-rb.org/guides ) .
9424
9525## License
9626
0 commit comments