active_model_serializer-呈现null

时间:2019-02-20 08:52:27

标签: active-model-serializers rails-api

我遇到的情况是响应为空:

#in a controller #show action

render json: @client.profile

我在ProfileSerializer中没有特殊设置,只是

class ProfileSerializer < ActiveModel::Serializer
  belongs_to :client
  attributes :id, ...#other attributes come here
end

在这种情况下,响应只是null,没有JSON结构。这是正常行为吗? 根据{{​​3}}:

A server MUST respond to a successful request to fetch an individual 
resource with a resource object or null provided as the response document’s 
primary data.

0 个答案:

没有答案