Quantcast
Channel: Software Habit
Viewing all articles
Browse latest Browse all 11

Ruby Tips #359 – Root Node for ActiveModel Serializers

$
0
0

To override your root nodes for ActiveModel serializers without a global config use the following. This makes a consistent API for clients regardless of model but still leaves your code flexible.

# Controller
render json: @liked, root: 'data'
 
# Returns a collection like so.
{
  "data" [{}, {}, {}]
}

Viewing all articles
Browse latest Browse all 11

Trending Articles