Update README.md

This commit is contained in:
jeffrey008 2017-04-13 09:41:51 +08:00 committed by GitHub
parent 29166b26b2
commit 7d89e26304

View File

@ -234,7 +234,7 @@ end
You can specify that serializers use the lower-camel key format at the config, class or instance level. You can specify that serializers use the lower-camel key format at the config, class or instance level.
````ruby ```ruby
ActiveModel::Serializer.setup do |config| ActiveModel::Serializer.setup do |config|
config.key_format = :lower_camel config.key_format = :lower_camel
@ -245,17 +245,17 @@ class BlogLowerCamelSerializer < ActiveModel::Serializer
end end
BlogSerializer.new(object, key_format: :lower_camel) BlogSerializer.new(object, key_format: :lower_camel)
```` ```
## Changing the default association key type ## Changing the default association key type
You can specify that serializers use unsuffixed names as association keys by default. You can specify that serializers use unsuffixed names as association keys by default.
````ruby ```ruby
ActiveModel::Serializer.setup do |config| ActiveModel::Serializer.setup do |config|
config.default_key_type = :name config.default_key_type = :name
end end
```` ```
This will build association keys like `comments` or `author` instead of `comment_ids` or `author_id`. This will build association keys like `comments` or `author` instead of `comment_ids` or `author_id`.
@ -932,7 +932,7 @@ now generates:
class PostSerializer < ApplicationSerializer class PostSerializer < ApplicationSerializer
attributes :id attributes :id
end end
```` ```
# Design and Implementation Guidelines # Design and Implementation Guidelines