In a Ruby 2/Rails 4 app, I am trying to use acts-as-taggable-on in conjunction with active_model_serializers in order to create a JSON API that would output my tags along with o
Fixed! Turns out to sideload the tags, the corresponding serializer must be defined. I did not know this, because the documentation seems to imply that having a serializer is optional, and some default will be used in the absence of one. Apparently this is not the case if you wish to use the include: true
option. Key in sight came from here, thanks very much!
For completeness, I'll show what I did. I created tag_serializer.rb
with the following code:
module ActsAsTaggableOn
class TagSerializer < ActiveModel::Serializer
attributes :id, :name
end
end
and now my JSON:
{
"tags": [
{
"id": "a33fc396-2428-11e3-8eeb-0800270f33f4",
"name": "test"
}
],
"documents": [
{
"id": "c41460fa-2427-11e3-8702-0800270f33f4",
"tag_ids": [
"a33fc396-2428-11e3-8eeb-0800270f33f4"
]
}
]
}