rails - 非资源方法的 kaminari 分页

rails - kaminari pagination to non resource method

kaminari 在我的应用程序中处理分页,例如,如果我希望任务索引可以分页,我只需要在 routes.rb:

中添加此代码
  concern :paginatable do
    get '(page/:page)', :action => :index, :on => :collection, :as => ''
  end

  resources :missions, only: [:index, :create, :show, :destroy], :concerns => :paginatable do
    post :done, on: :member
  end

并在 missions_controller.rb 中:

  def index
    missions = Mission.all
    if params[:page]
      missions = missions.page(params[:page])
    end
    respond_with missions
  end

但是如果我在 mission_controller.rb 中有另一种方法怎么办 - 用户任务:

  def user
    missions = Mission.where(recipient_id: current_user.id)
        if params[:page]
      missions = missions.page(params[:page])
    end
    respond_with missions
  end

routes.rb中是这样配置的:

  get 'users_missions' => 'missions#user'

如何配置 routes.rb 以支持此方法的分页?

通过在routes.rb中添加另一行解决:

  get 'users_missions/page/:page' => 'missions#user'

在上一个 (get 'users_missions' => 'missions#user') 旁边