There is still refactoring of internals to do, particularly around the
proxies/runner, but this adds 1.0 support for writes:
def create
employee = EmployeeResource.build(params)
if employee.save
render jsonapi: employee
else
render jsonapi_errors: employee
end
end
def update
employee = EmployeeResource.find(params)
if employee.update_attributes
render jsonapi: employee
else
render jsonapi_errors: employee
end
end
def destroy
employee = EmployeeResource.find(params)
if employee.destroy
render jsonapi: employee
else
render jsonapi_errors: employee
end
end
This will honor the attribute types, see spec/persistence_spec.rb for
detailed usage.
Questions:
save and update_attributes functionally do the same thing, and the
alias is just to match rails convention. Is there anything better we can
do here?
Other notes:
All tests now pass
This commit wires-up write functionality, it does not refactor the
existing write functionality. This can come later.
sort and filter customizations now optionally accept a type. If
given a type, we will create a sort-only or filter-only attribute
under-the-hood. We will still raise errors if not given a type, or if
the attribute was specifically marked unsortable/unfilterable.
Adds jsonapi_errorable as a dependency, which sets us up to remove
the top-level jsonapi_suite gem altogether.
Moves render_jsonapi completely from Base - this is now
proxy.to_jsonapi. It will still respect def default_render_jsonapi_options;end if defined in the controller.
There is still refactoring of internals to do, particularly around the proxies/runner, but this adds 1.0 support for writes:
This will honor the attribute types, see
spec/persistence_spec.rb
for detailed usage.Questions:
save
andupdate_attributes
functionally do the same thing, and the alias is just to match rails convention. Is there anything better we can do here?Other notes:
sort
andfilter
customizations now optionally accept a type. If given a type, we will create a sort-only or filter-only attribute under-the-hood. We will still raise errors if not given a type, or if the attribute was specifically marked unsortable/unfilterable.jsonapi_errorable
as a dependency, which sets us up to remove the top-leveljsonapi_suite
gem altogether.render_jsonapi
completely fromBase
- this is nowproxy.to_jsonapi
. It will still respectdef default_render_jsonapi_options;end
if defined in the controller.Resource#typecast
convenience method.