我正在尝试在没有时区指示符的情况下以 UTC 格式呈现我的响应中的时间戳。我正在使用 jsonapi-serializer 序列化我的资源,但是它不提供配置时间戳格式的方法。我不得不像这样包装每个时间戳属性作为解决方法:
class LessonSerializer
include JSONAPI::Serializer
attributes :starts_at, :ends_at, :created_at, :updated_at
attribute :starts_at do |object|
object.starts_at.utc
end
#other timestamps attributes
end
我正在尝试找到一种更好的方法来做到这一点,因为我正在为所有资源实现这个,而不仅仅是这个序列化器。