我正在使用char [][]
有效模型Serializer和Pagination Serializer。这可能是Pagination Serializer
master
这是我的渲染代码。
# pagination collection serializer
class PaginationSerializer < ActiveModel::Serializer::CollectionSerializer
def initialize(object, options = {})
meta_key = options[:meta_key] || :meta
options[meta_key] ||= {}
options[meta_key][:pagination] = {
current_page: object.current_page,
next_page: object.next_page,
prev_page: object.prev_page,
total_pages: object.total_pages,
total_count: object.total_count,
size: object.total_count
}
super(object, options)
end
end
结果上没有元键。从0.10.0.RC3升级到master后会发生这种情况。有什么想法吗?
答案 0 :(得分:0)
# my_app/app/application_controller.rb
...
def pagination_dict(object)
{
current_page: object.current_page,
next_page: object.next_page,
prev_page: object.prev_page,
total_pages: object.total_pages,
total_count: object.total_count
}
end
# my_app/config/initializers/active_model_serializer.rb
ActiveModel::Serializer.config.adapter = :json
渲染代码:
render json: formulas, meta: pagination_dict(formulas)