Как я могу исправить JSONAPI::Serializable::UndefinedSerializableClass

Как я могу исправить:

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'

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
Другие вопросы по тегам