【问题标题】:How i can fix JSONAPI::Serializable::UndefinedSerializableClass我如何修复 JSONAPI::Serializable::UndefinedSerializableClass
【发布时间】:2018-03-03 23:53:46
【问题描述】:
我该如何解决:
ERROR: JSONAPI::Serializable::UndefinedSerializableClass: No
serializable class defined for Post
app/controllers/api/v1/posts_controller.rb:20:in `index'
使用这个宝石:
gem 'jsonapi_suite'
gem 'jsonapi-rails'
【问题讨论】:
标签:
ruby-on-rails
json-api
jsonapi-resources
【解决方案1】:
您需要将class 参数设置为render_jsonapi。
# app/controllers/api/v1/posts_controller.rb
module Api
module V1
class PostsController < Api::V1::ApplicationController
# ...
def index
posts = Post.all
render_jsonapi(posts, class: { Post: Api::V1::SerializablePost })
end
# ...
end
end
end