README.md in cheap_ams-0.10.8 vs README.md in cheap_ams-0.10.10

- old
+ new

@@ -1,8 +1,8 @@ # ActiveModel::Serializer -[![Build Status](https://travis-ci.org/rails-api/active_model_serializers.svg)](https://travis-ci.org/rails-api/active_model_serializers) +[![Build Status](https://travis-ci.org/rails-api/active_model_serializers.svg)](https://travis-ci.org/rails-api/active_model_serializers) <a href="https://codeclimate.com/github/rails-api/active_model_serializers"><img src="https://codeclimate.com/github/rails-api/active_model_serializers/badges/gpa.svg" /></a> <a href="https://codeclimate.com/github/rails-api/active_model_serializers/coverage"><img src="https://codeclimate.com/github/rails-api/active_model_serializers/badges/coverage.svg" /></a> _Windows Build Status -_ [![Build status](https://ci.appveyor.com/api/projects/status/x6xdjydutm54gvyt/branch/master?svg=true)](https://ci.appveyor.com/project/joaomdmoura/active-model-serializers/branch/master) @@ -136,10 +136,27 @@ render json: @post, meta: { total: 10 }, meta_key: "custom_meta" ``` `meta` will only be included in your response if you are using an Adapter that supports `root`, as JsonAPI and Json adapters, the default adapter (FlattenJson) doesn't have `root`. +### Using a serializer without `render` + +At times, you might want to use a serializer without rendering it to the view. For those cases, you can create an instance of `ActiveModel::SerializableResource` with +the resource you want to be serialized and call `.serializable_hash`. + +```ruby +def create + @message = current_user.messages.create!(message_params) + MessageCreationWorker.perform(serialized_message) + head 204 +end + +def serialized_message + ActiveModel::SerializableResource.new(@message).serializable_hash +end +``` + ### Overriding association methods If you want to override any association, you can use: ```ruby @@ -185,16 +202,16 @@ #### JSONAPI This adapter follows 1.0 of the format specified in [jsonapi.org/format](http://jsonapi.org/format). It will include the associated resources in the `"included"` member when the resource names are included in the -`include` option. +`include` option. Including nested associated resources is also supported. ```ruby - render @posts, include: ['authors', 'comments'] + render @posts, include: ['author', 'comments', 'comments.author'] # or - render @posts, include: 'authors,comments' + render @posts, include: 'author,comments,comments.author' ``` ## Installation Add this line to your application's Gemfile: @@ -281,10 +298,10 @@ The cache support is optimized to use the cached object in multiple request. An object cached on a ```show``` request will be reused at the ```index```. If there is a relationship with another cached serializer it will also be created and reused automatically. **[NOTE] Every object is individually cached.** -**[NOTE] The cache is automatically expired after update an object but it's not deleted.** +**[NOTE] The cache is automatically expired after an object is updated, but it's not deleted.** ```ruby cache(options = nil) # options: ```{key, expires_in, compress, force, race_condition_ttl}``` ```