I'm new to AMS. I created a table named 'tags'. Here it is.
create_table "tags", force: :cascade do |t|
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
The data type of id is Integer. However the output is String.
"data": [
{
"id": 1,
"type": "tags",
"attributes": {
"name": "autem"
}
}
]
"data": [
{
"id": "1",
"type": "tags",
"attributes": {
"name": "autem"
}
}
]
class Tag < ApplicationRecord
end
module Api
module V1
class TagsController < ApplicationController
def index
@tags = Tag.all
render json: @tags
end
end
end
end
class TagSerializer < ActiveModel::Serializer
attributes :id, :name
end
ActiveModelSerializers Version _0.10.0_:
Output of ruby -e "puts RUBY_DESCRIPTION": ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]
OS Type & Version: EI Capitan 10.11.2
Integrated application and version _(e.g., Rails, Grape, etc)_:
_(e.g., provide any applicable backtraces from your application)_
None.
Thank U in advance.
Hi @polarlights - looks like you're outputting jsonapi. According to the jsonapi spec, id must be a string: http://jsonapi.org/format/#document-resource-objects
Yep. My fault. @richmolj Thank you very much! 馃憤
Most helpful comment
Hi @polarlights - looks like you're outputting jsonapi. According to the jsonapi spec, id must be a string: http://jsonapi.org/format/#document-resource-objects