0

我该如何解决:

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'
4

1 回答 1

2

您需要将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
于 2017-09-22T11:48:52.120 回答