Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Documentation on Serializers and Rendering #2104

Merged
merged 1 commit into from
May 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Fixes:

Misc:

- [#2104](https://github.com/rails-api/active_model_serializers/pull/2104) Documentation for serializers and rendering. (@cassidycodes)
- [#2081](https://github.com/rails-api/active_model_serializers/pull/2081) Documentation for `include` option in adapters. (@charlie-wasp)

### [v0.10.5 (2017-03-07)](https://github.com/rails-api/active_model_serializers/compare/v0.10.4...v0.10.5)
Expand Down Expand Up @@ -79,7 +80,7 @@ Misc:

- [#1878](https://github.com/rails-api/active_model_serializers/pull/1878) Cache key generation for serializers now uses `ActiveSupport::Cache.expand_cache_key` instead of `Array#join` by default and is also overridable. This change should be backward-compatible. (@markiz)

- [#1799](https://github.com/rails-api/active_model_serializers/pull/1799) Add documentation for setting the adapter. (@ScottKbka)
- [#1799](https://github.com/rails-api/active_model_serializers/pull/1799) Add documentation for setting the adapter. (@cassidycodes)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you change your username? strange that this would be wrong.

- [#1909](https://github.com/rails-api/active_model_serializers/pull/1909) Add documentation for relationship links. (@vasilakisfil, @NullVoxPopuli)
- [#1959](https://github.com/rails-api/active_model_serializers/pull/1959) Add documentation for root. (@shunsuke227ono)
- [#1967](https://github.com/rails-api/active_model_serializers/pull/1967) Improve type method documentation. (@yukideluxe)
Expand Down
22 changes: 18 additions & 4 deletions docs/general/rendering.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ link(:link_name) { url_for(controller: 'controller_name', action: 'index', only_

#### include

PR please :)
See [Adapters: Include Option](/docs/general/adapters.md#include-option).

#### Overriding the root key

Expand Down Expand Up @@ -260,15 +260,29 @@ Note that by using a string and symbol, Ruby will assume the namespace is define

#### serializer

PR please :)
Specify which serializer to use if you want to use a serializer other than the default.

For a single resource:

```ruby
@post = Post.first
render json: @post, serializer: SpecialPostSerializer
```

To specify which serializer to use on individual items in a collection (i.e., an `index` action), use `each_serializer`:

```ruby
@posts = Post.all
render json: @posts, each_serializer: SpecialPostSerializer
```

#### scope

PR please :)
See [Serializers: Scope](/docs/general/serializers.md#scope).

#### scope_name

PR please :)
See [Serializers: Scope](/docs/general/serializers.md#scope).

## Using a serializer without `render`

Expand Down
19 changes: 17 additions & 2 deletions docs/general/serializers.md
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,26 @@ The serialized value for a given key. e.g. `read_attribute_for_serialization(:ti

#### #links
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra # in front of links

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you man that #### #links should be #### links? Many h4 headers in this document have a # as part of the text. I believe this is to indicate that they are instance methods. Would you like me to remove all of them? e.g. ln 238, ln 252

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh you're right about instance methods. Code blindness...


PR please :)
Allows you to modify the `links` node. By default, this node will be populated with the attributes set using the [::link](#link) method. Using `links: nil` will remove the `links` node.

```ruby
ActiveModelSerializers::SerializableResource.new(
@post,
adapter: :json_api,
links: {
self: {
href: 'http://example.com/posts',
meta: {
stuff: 'value'
}
}
}
)
```

#### #json_key

PR please :)
Returns the key used by the adapter as the resource root. See [root](#root) for more information.

## Examples

Expand Down