rails-api/active_model_serializers — pull request #264 by vad4msiu (2013-04-04 11:23:32+00:00)
Title: Support for setting root element

This pull request solves this problem:

config/initializers/active_model_serializers.rb
```ruby
ActiveSupport.on_load(:active_model_serializers) do
ActiveModel::Serializer.root = false
ActiveModel::ArraySerializer.root = false
end
```
app/serializers/api/dispatcher/v1/panel_serializer.rb
```ruby
class Api::Dispatcher::V1::PanelSerializer < ActiveModel::Serializer
...
end
```
app/serializers/api/frontend/v1/base_serializer.rb
```ruby
class Api::Frontend::V1::BaseSerializer < ActiveModel::Serializer
root true
embed :ids
end
```
app/serializers/api/frontend/v1/panel_serializer.rb
```ruby
class Api::Frontend::V1::PanelSerializer < Api::Frontend::V1::BaseSerializer
...
end
```
app/serializers/api/frontend/v1/tag_serializer.rb
```ruby
class Api::Frontend::V1::TagSerializer < Api::Frontend::V1::BaseSerializer
...
end
```

```ruby
Api::Dispatcher::V1::PanelSerializer.new(panel).as_json
=> { :id => 1, ... }

Api::Frontend::V1::PanelSerializer.new(panel).as_json
=> { :panel => { :id => 1, ... }}

Api::Frontend::V1::TagSerializer.new(tag).as_json
=> { :tag => { :id => 1, ... }}
```