如何覆盖active_model_serializers

时间:2016-03-29 12:58:07

标签: ruby-on-rails-4 kaminari active-model-serializers json-api

我想覆盖与active_model_serializers关联的kaminari生成的分页链接。我如何实现这一点,this page没有关于覆盖的信息 enter image description here

此外,生成的链接按此顺序>> {" self"," first"," prev"," next"," last"}

我希望他们按此顺序代替>> {"首先"," 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

1 个答案:

答案 0 :(得分:0)

覆盖文件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并执行任何操作。