如何覆盖 active_model_serializers 生成的分页链接
How do I Override pagination links generated by active_model_serializers
我想覆盖 active_model_serializers
与 kaminari
关联生成的分页链接。我如何实现这一点,this page 上没有关于覆盖的信息
此外,生成的链接是这样排序的>> {"self", "first", "prev", "next", "last"}
我希望它们按此顺序排列>> {"first", "prev", "self", "next", "last"}
下面是来自管理员控制器的索引方法的片段:
def index
@search = Admin.search(params[:q])
if params[:page]
@admins = @search.result(:distinct => true).page(params[:page][:number])
else
@admins = @search.result(:distinct => true).page(1)
end
@admins_json = ActiveModel::SerializableResource.new(@admins)
@admins_json = @admins_json.to_json(serialization_context: ActiveModelSerializers::SerializationContext.new(request))
@page_entries_info = view_context.page_entries_info @admins
# render json: @admins
respond_to do |format|
format.html
format.js
format.json { render :json => @admins, meta: {:page_entries_info => @page_entries_info} }
end
end
覆盖文件pagination_links.rb
将/home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/bundler/gems/active_model_serializers-afe3c938070d/lib/active_model_serializers/adapter/json_api/pagination_links.rb
的内容复制到#lib/active_model_serializers/adapter/json_api/pagination_links.rb
中,随心所欲。
我想覆盖 active_model_serializers
与 kaminari
关联生成的分页链接。我如何实现这一点,this page 上没有关于覆盖的信息
此外,生成的链接是这样排序的>> {"self", "first", "prev", "next", "last"}
我希望它们按此顺序排列>> {"first", "prev", "self", "next", "last"}
下面是来自管理员控制器的索引方法的片段:
def index
@search = Admin.search(params[:q])
if params[:page]
@admins = @search.result(:distinct => true).page(params[:page][:number])
else
@admins = @search.result(:distinct => true).page(1)
end
@admins_json = ActiveModel::SerializableResource.new(@admins)
@admins_json = @admins_json.to_json(serialization_context: ActiveModelSerializers::SerializationContext.new(request))
@page_entries_info = view_context.page_entries_info @admins
# render json: @admins
respond_to do |format|
format.html
format.js
format.json { render :json => @admins, meta: {:page_entries_info => @page_entries_info} }
end
end
覆盖文件pagination_links.rb
将/home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/bundler/gems/active_model_serializers-afe3c938070d/lib/active_model_serializers/adapter/json_api/pagination_links.rb
的内容复制到#lib/active_model_serializers/adapter/json_api/pagination_links.rb
中,随心所欲。