Ruby on rails Rails-从JSON中删除时间戳

Ruby on rails Rails-从JSON中删除时间戳,ruby-on-rails,json,ruby,active-model-serializers,serialization,Ruby On Rails,Json,Ruby,Active Model Serializers,Serialization,我正在使用AMS为我的Rails API创建JSON输出。当前,当它呈现博客列表时。用户的时间戳仍然显示在我的输出中,即使它不存在于我的序列化程序中 博客序列化程序: class BlogSerializer < ActiveModel::Serializer attributes :id, :user has_many :posts end class BlogSerializer

我正在使用AMS为我的Rails API创建JSON输出。当前,当它呈现博客列表时。用户的时间戳仍然显示在我的输出中,即使它不存在于我的序列化程序中

博客序列化程序:

class BlogSerializer < ActiveModel::Serializer
  attributes :id, :user
  has_many :posts
end
class BlogSerializer
用户序列化程序:

class UserSerializer < ActiveModel::Serializer
  attributes :username
end
class UserSerializer
博客控制器:

class BlogsController < ApplicationController

  def index
    @blogs = Blog.all

    render json:  @blogs
  end
end
class BlogsController

为什么仍然为用户呈现时间戳

您需要指定序列化程序

添加
每个序列化程序:BlogSerializer
呈现json

class BlogsController < ApplicationController

    def index
        @blogs = Blog.all

        render json:  @blogs, each_serializer: BlogSerializer 
    end
end
class BlogsController

以及如何将
用户
博客
关联?

您需要指定序列化程序

添加
每个序列化程序:BlogSerializer
呈现json

class BlogsController < ApplicationController

    def index
        @blogs = Blog.all

        render json:  @blogs, each_serializer: BlogSerializer 
    end
end
class BlogsController

以及如何将
用户
博客
关联?

显示您的控制器您是否尝试重新启动服务器?@MikhailKatrinadded@inye是的!你的控制器如何重新启动服务器?@MikhailKatrinadded@inye是的!没有工作博客--属于:海报,类名:“用户”,外键:“海报id”用户--有很多:博客你应该将所有关联添加到序列化程序到博客--属于:海报,类名:“用户”,外键:“海报id”用户--有很多:博客你也应该将所有关联添加到序列化程序