Skip to content

Commit

Permalink
Merge 74d3398 into 9436d73
Browse files Browse the repository at this point in the history
  • Loading branch information
fab committed Feb 1, 2014
2 parents 9436d73 + 74d3398 commit ffcb9ed
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
27 changes: 23 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ Currently `ActiveModel::Serializers` expects objects to implement
read\_attribute\_for\_serialization. That's all you need to do to have
your POROs supported.

# ActiveModel::Serializer

All new serializers descend from ActiveModel::Serializer

# render :json

In your controllers, when you use `render :json`, Rails will now first search
Expand Down Expand Up @@ -726,6 +722,29 @@ end

The caching interface uses `Rails.cache` under the hood.

# ApplicationSerializer

By default, new serializers descend from ActiveModel::Serializer. However, if you wish to share behaviour across your serializers you can create an ApplicationSerializer at ```app/serializers/application_serializer.rb```:

```ruby
class ApplicationSerializer < ActiveModel::Serializer
end
```

Any newly generated serializers will automatically descend from ApplicationSerializer.

```
$ rails g serializer post
```

now generates:

```ruby
class PostSerializer < ApplicationSerializer
attributes :id
end
````

# Design and Implementation Guidelines

## Keep it Simple
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def parent_class_name
if options[:parent]
options[:parent]
elsif (ns = Rails::Generators.namespace) && ns.const_defined?(:ApplicationSerializer) ||
defined?(::ApplicationSerializer)
(Object.const_get(:ApplicationSerializer) rescue nil)
'ApplicationSerializer'
else
'ActiveModel::Serializer'
Expand Down

0 comments on commit ffcb9ed

Please sign in to comment.