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
+81-30Lines changed: 81 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,8 +2,6 @@
2
2
3
3
[](https://gitter.im/cerebris/jsonapi-resources?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4
4
5
-
**_NOTE: There is a Rails 5 branch that is a work in progress. In addition to some changes for Rails 5 support it contains some monkey patches (in `test_helper.rb`) to allow existing tests to pass with Rails 5.0.0.beta1.1_. Things may break with future changes to Rails. If you are using RAILS 5 it is recommended that you use the rails 5 branch.**
6
-
7
5
`JSONAPI::Resources`, or "JR", provides a framework for developing a server that complies with the
8
6
[JSON API](http://jsonapi.org/) specification.
9
7
@@ -21,23 +19,29 @@ backed by ActiveRecord models or by custom objects.
Resources define the public interface to your API. A resource defines which attributes are exposed, as well as
73
77
relationships to other resources.
74
78
75
-
Resource definitions should by convention be placed in a directory under app named resources, `app/resources`. The class
76
-
name should be the single underscored name of the model that backs the resource with `_resource.rb` appended. For example,
79
+
Resource definitions should by convention be placed in a directory under app named resources, `app/resources`. The file name should be the single underscored name of the model that backs the resource with `_resource.rb` appended. For example,
77
80
a `Contact` model's resource should have a class named `ContactResource` defined in a file named `contact_resource.rb`.
78
81
79
82
#### JSONAPI::Resource
@@ -155,6 +158,36 @@ In the above example vehicles are immutable. A call to `/vehicles` or `/vehicles
155
158
of either `car` or `boat`. But calls to PUT or POST a `car` must be made to `/cars`. The rails models backing the above
156
159
code use Single Table Inheritance.
157
160
161
+
#### Context
162
+
163
+
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.
0 commit comments