mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 14:56:50 +00:00
Merge pull request #157 from frodsan/fix_readme
update travis link [ci skip]
This commit is contained in:
commit
6b88f1b6ef
@ -1,4 +1,4 @@
|
|||||||
[](http://travis-ci.org/josevalim/active_model_serializers)
|
[](http://travis-ci.org/rails-api/active_model_serializers)
|
||||||
|
|
||||||
# Purpose
|
# Purpose
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ The easiest way to create a new serializer is to generate a new resource, which
|
|||||||
will generate a serializer at the same time:
|
will generate a serializer at the same time:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ rails g resource post title:string body:string
|
$ rails g resource post title:string body:string
|
||||||
```
|
```
|
||||||
|
|
||||||
This will generate a serializer in `app/serializers/post_serializer.rb` for
|
This will generate a serializer in `app/serializers/post_serializer.rb` for
|
||||||
@ -64,7 +64,7 @@ end
|
|||||||
```
|
```
|
||||||
|
|
||||||
In this case, Rails will look for a serializer named `PostSerializer`, and if
|
In this case, Rails will look for a serializer named `PostSerializer`, and if
|
||||||
it exists, use it to serialize the `Post`.
|
it exists, use it to serialize the `Post`.
|
||||||
|
|
||||||
This also works with `respond_with`, which uses `to_json` under the hood. Also
|
This also works with `respond_with`, which uses `to_json` under the hood. Also
|
||||||
note that any options passed to `render :json` will be passed to your
|
note that any options passed to `render :json` will be passed to your
|
||||||
@ -386,7 +386,7 @@ Alternatively, you can choose to embed only the ids or the associated objects pe
|
|||||||
```ruby
|
```ruby
|
||||||
class PostSerializer < ActiveModel::Serializer
|
class PostSerializer < ActiveModel::Serializer
|
||||||
attributes :id, :title, :body
|
attributes :id, :title, :body
|
||||||
|
|
||||||
has_many :comments, embed: :objects
|
has_many :comments, embed: :objects
|
||||||
has_many :tags, embed: :ids
|
has_many :tags, embed: :ids
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user