kaminari

Get kaminari pagination links in the JSON generated by the active model serializer

泪湿孤枕 提交于 2019-12-24 16:33:54
问题 I am trying to convert @admins to JSON using the AdminSerializer #app/serializers/admin_serializer.rb class AdminSerializer < ActiveModel::Serializer attributes :id, :email, :access_locked? end where Admins is>> @admins = @search.result(:distinct => true).page(params[:page][:number]).per(10) and @search = Admin.search(params[:q]) When I execute this command>> ActiveModel::SerializableResource.new(@admins.to_a).as_json I do get the desired JSON, but the pagination links are missing from the

customize kaminari pagination template

拟墨画扇 提交于 2019-12-24 11:20:43
问题 I'm having difficulty customizing the default kaminari template. I've used the generator to create kaminari template files. In kaminari/paginator.html.haml: = paginator.render do %nav.pagination All I want to do is access the actionview helpers within this, like link_to, or render. I've searched the source code and I can't find any incline of the helper being passed to this render method. Essentially, being able to do this: = paginator.render do %nav.pagination = render :partial => 'custom

How can I set initial offset for first page in kaminari?

不羁岁月 提交于 2019-12-24 05:25:24
问题 I need to implement some logic for to show 3 elements on the first page and by 1 element on all the next. For the first page there is no problems: items = @model.limit(@first_page_items) and for all the next ones i tried: @model.offset(@first_page_items).page(@current_page - 1).per(@per) #makes no offset at all - all the items going from the beginning @model.page(@current_page - 1).per(@per).offset(@first_page_items) #produces 4-th element on the second page and stays on it for ever What am I

Kaminari is slow with COUNT(*) on a huge table in Postgres [duplicate]

时光怂恿深爱的人放手 提交于 2019-12-24 00:49:06
问题 This question already has answers here : How do I speed up counting rows in a PostgreSQL table? (6 answers) Closed 5 years ago . I'm using the Kaminari gem to paginate a query on a large table (~1.5MM rows). While fetching the actual results pages is quite quick (~20ms), kaminari's added SELECT COUNT(*) WHERE .... is excruciatingly slow, and adds several extra seconds to the execution time. Is there a way to approximate the number of results instead? 回答1: Quick estimate for whole table For a

kaminari undefined method `total_pages'

我只是一个虾纸丫 提交于 2019-12-23 07:39:09
问题 While using kaminari, I got an error. Gemfile: # gem 'will_paginate', '~> 3.0.6' # gem 'will_paginate-bootstrap' gem 'kaminari' lists_controller.rb def index if params[:tag] @lists = List.tagged_with(params[:tag]).order(created_at: :desc).paginate(page:params[:page], per_page: 3 ) else @lists = List.all.order(created_at: :desc) end end I also user .page params[:page].per(2) follow .order(created_at: :desc) but not work views/lists/index.html.erb <%= paginate @lists %> the error is here

jquery-rails breaks kaminari?

删除回忆录丶 提交于 2019-12-21 23:15:54
问题 I updated my Rails 3.0.7 application to use kaminari 0.12.4 (up from 0.10.4) for pagination and jquery-rails 1.0.9 and it seemed to break pagination. I've regenerated the kaminari views since they are different but for some reason ajax isn't working. <%= javascript_include_tag :defaults %> is included. Which produces this in the browser: <script src="/javascripts/jquery.js?1306353646" type="text/javascript"></script> <script src="/javascripts/jquery-ui.js?1306368501" type="text/javascript"><

Rails caching: Expiring multiple pages for one action

ぐ巨炮叔叔 提交于 2019-12-21 12:42:49
问题 I've set up action caching (with sweepers, but I guess that's irrelevant here) in my app, and so far it works great except for one thing: I use Kaminari for pagination, and thus when I execute expire_action on my action it only expires the first page. As I know caching won't work when using the query string for specifying the page, I've set up a route so the pages are appended to the end of the url (for example /people/123/page/2). I'll add more info to this post if necessary, but I'm

Ruby/Rails - kaminari undefined method pagination errors

落花浮王杯 提交于 2019-12-21 05:44:22
问题 I'm not sure what I did, but kaminari has started acting weird in my app. In my controller: @producers = Producer.order(:name).page(params[:page]) view: <%= paginate @producers %> results in: undefined method `num_pages' for #<ActiveRecord::Relation:0x000001026e6308> If I add .per in my controller: @producers = Producer.order(:name).page(params[:page]).per(25) I get undefined local variable or method `per' for #<ActiveRecord::Relation:0x0000010928ef60> Finally, strangely, if I move my .order(

total_pages return in pagination with rails and kaminari

℡╲_俬逩灬. 提交于 2019-12-20 04:24:06
问题 i want a pagination in my page, im using ruby and kaminari to this. class ServicesController < ApplicationController def index /@services = Service.order(name: :asc)/ @organs = Admin::Organ.all @services = @services.order(created_at: :desc).paginate(page:params[:page], per_page: 3 ) end this code, my control try paginate pages 3 to 3. In views: <%= paginate @organ.services %> As i want call the services with relationship to each organ i insert que last code im my view. The result are:

Is there any possible way to fix the url that Kaminari pagination generates?

扶醉桌前 提交于 2019-12-19 03:24:10
问题 I was implementing a chat system to my app, in which only the list of comments will be reloaded with ajax submit. Kaminari pagination is used in there, but it gets weird string in its url like this after new comment was submit. example-website.com/users/mike/refresh_part?_=1356906069855&page=2 and it gets more strange argument parameters in its url when comment was submit in the other controller. Only when it was macthed with spamming error Generated url: example-website.com/shop/walmart