I want to override the Pagination links generated by the active_model_serializers
in association with kaminari
. How do I achieve this, there is no information on this page about overriding
Moreover, the links generated are in this order>> {"self", "first", "prev", "next", "last"}
I want them to be in this order instead>> {"first", "prev", "self", "next", "last"}
Below is the snippet of index method from admins controller:
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
Override the file pagination_links.rb
Copy the contents of /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
into #lib/active_model_serializers/adapter/json_api/pagination_links.rb
and do whatever you want.