mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
reverting PR #909 and adding json api usage advise on readme
This commit is contained in:
parent
12adb2e6d4
commit
a40df8fd3d
@ -8,7 +8,7 @@ AMS does this through two components: **serializers** and **adapters**.
|
|||||||
Serializers describe _which_ attributes and relationships should be serialized.
|
Serializers describe _which_ attributes and relationships should be serialized.
|
||||||
Adapters describe _how_ attributes and relationships should be serialized.
|
Adapters describe _how_ attributes and relationships should be serialized.
|
||||||
|
|
||||||
By default AMS will use the JsonApi Adapter that follows RC4 of the format specified in [jsonapi.org/format](http://jsonapi.org/format).
|
By default AMS will use the **Json Adapter**. But we strongly advise you to use JsonApi Adapter that follows RC4 of the format specified in [jsonapi.org/format](http://jsonapi.org/format).
|
||||||
Check how to change the adapter in the sections bellow.
|
Check how to change the adapter in the sections bellow.
|
||||||
|
|
||||||
# RELEASE CANDIDATE, PLEASE READ
|
# RELEASE CANDIDATE, PLEASE READ
|
||||||
@ -50,17 +50,17 @@ end
|
|||||||
```
|
```
|
||||||
|
|
||||||
Generally speaking, you as a user of AMS will write (or generate) these
|
Generally speaking, you as a user of AMS will write (or generate) these
|
||||||
serializer classes. If you want to use a different adapter, such as a normal Json adapter without the JsonApi conventions, you can
|
serializer classes. If you want to use a different adapter, such as a JsonApi, you can
|
||||||
change this in an initializer:
|
change this in an initializer:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
ActiveModel::Serializer.config.adapter = ActiveModel::Serializer::Adapter::Json
|
ActiveModel::Serializer.config.adapter = ActiveModel::Serializer::Adapter::JsonApi
|
||||||
```
|
```
|
||||||
|
|
||||||
or
|
or
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
ActiveModel::Serializer.config.adapter = :json
|
ActiveModel::Serializer.config.adapter = :json_api
|
||||||
```
|
```
|
||||||
|
|
||||||
You won't need to implement an adapter unless you wish to use a new format or
|
You won't need to implement an adapter unless you wish to use a new format or
|
||||||
|
|||||||
@ -6,7 +6,7 @@ module ActiveModel
|
|||||||
|
|
||||||
included do |base|
|
included do |base|
|
||||||
base.config.array_serializer = ActiveModel::Serializer::ArraySerializer
|
base.config.array_serializer = ActiveModel::Serializer::ArraySerializer
|
||||||
base.config.adapter = :json_api
|
base.config.adapter = :json
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -4,7 +4,7 @@ module ActionController
|
|||||||
module Serialization
|
module Serialization
|
||||||
class AdapterSelectorTest < ActionController::TestCase
|
class AdapterSelectorTest < ActionController::TestCase
|
||||||
class MyController < ActionController::Base
|
class MyController < ActionController::Base
|
||||||
def render_using_the_initializer_defined_adapter
|
def render_using_default_adapter
|
||||||
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
||||||
render json: @profile
|
render json: @profile
|
||||||
end
|
end
|
||||||
@ -23,7 +23,7 @@ module ActionController
|
|||||||
tests MyController
|
tests MyController
|
||||||
|
|
||||||
def test_render_using_default_adapter
|
def test_render_using_default_adapter
|
||||||
get :render_using_the_initializer_defined_adapter
|
get :render_using_default_adapter
|
||||||
assert_equal '{"name":"Name 1","description":"Description 1"}', response.body
|
assert_equal '{"name":"Name 1","description":"Description 1"}', response.body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
4
test/fixtures/poro.rb
vendored
4
test/fixtures/poro.rb
vendored
@ -1,5 +1,3 @@
|
|||||||
ActiveModel::Serializer.config.adapter = :json
|
|
||||||
|
|
||||||
class Model
|
class Model
|
||||||
def initialize(hash={})
|
def initialize(hash={})
|
||||||
@attributes = hash
|
@attributes = hash
|
||||||
@ -66,7 +64,7 @@ Author = Class.new(Model)
|
|||||||
Bio = Class.new(Model)
|
Bio = Class.new(Model)
|
||||||
Blog = Class.new(Model)
|
Blog = Class.new(Model)
|
||||||
Role = Class.new(Model)
|
Role = Class.new(Model)
|
||||||
User = Class.new(Model)
|
User = Class.new(Model)
|
||||||
Location = Class.new(Model)
|
Location = Class.new(Model)
|
||||||
Place = Class.new(Model)
|
Place = Class.new(Model)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user