[英]ActiveModel serializers under namespace not working
我有以下序列化程序/serializers/api/club_serializer.rb:
class Api::ClubSerializer < ActiveModel::Serializer
cached
attributes :id, :name, :created_at
end
和下面的方法 /controllers/api/clubs_controller.rb
module Api
class ClubsController < BaseController
include ActionController::ImplicitRender
include ActionController::MimeResponds
# GET /clubs
def index
@clubs = Club.all
render json: @clubs, serializer: ClubSerializer
end
这似乎无法正常工作,因为我删除了名称,它仍然显示所有字段的名称。
我如何更改它以使其有效?
你现在这样做的方式:
render json: @clubs, namespace: Api
请参阅: https : //github.com/rails-api/active_model_serializers/blob/0-10-stable/docs/general/rendering.md#namespace
为什么不:
render json: @clubs, each_serializer: ::Api::ClubSerializer
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.