We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 4f37205 + 9e8b6d4 commit e9bcc4eCopy full SHA for e9bcc4e
1 file changed
README.md
@@ -177,6 +177,14 @@ end
177
class PeopleController < ApplicationController
178
179
end
180
+
181
+# Assuming you don't permit user_id (so the client won't assign a wrong user to own the object)
182
+# you can ensure the current user is assigned the record by using the controller's context hash.
183
+class PeopleResource < JSONAPI::Resource
184
+ before_save do
185
+ @model.user_id = context[:current_user].id if @model.new_record?
186
+ end
187
+end
188
```
189
190
You can put things that affect serialization and resource configuration into the context.
0 commit comments