total_pages return in pagination with rails and kaminari

后端 未结 3 1646
礼貌的吻别
礼貌的吻别 2021-01-23 15:09

i want a pagination in my page, im using ruby and kaminari to this.



        
相关标签:
3条回答
  • 2021-01-23 15:21

    try this

    Old code

    @services = @services.order(created_at: :desc).paginate(page:params[:page], per_page: 3 )
    

    New code

    @services = Service.order(created_at: :desc).paginate(page:params[:page], per_page: 3 )
    
    0 讨论(0)
  • 2021-01-23 15:24

    I had a similar issue, it was because the commontator gem was bringing in methods from will_paginate and overriding the base ActiveRecord class.

    The error was in the call stack for the page_entries_info method which seems to be a common method name between both libraries.

    To fix, you can explicitly reference the method with this:

    So the view code:

    <%= Kaminari::Helpers::HelperMethods.page_entries_info @events %>
    <%= link_to "Next", path_to_next_page(@events) %>
    <%= link_to "Prev", path_to_prev_page(@events) %>
    

    and in an initializer (initializers/kaminari_config.rb)

    module Kaminari
      module Helpers
        module HelperMethods
          extend ActionView::Helpers::TranslationHelper
          module_function :page_entries_info
        end
      end
    end
    
    0 讨论(0)
  • 2021-01-23 15:39

    Try changing your controller code like the following:

    class ServicesController < ApplicationController
        def index
          @organs = Admin::Organ.all
          @services = Service.order(created_at: :desc).page(params[:page]).per(3)
        end
    end
    
    0 讨论(0)
提交回复
热议问题