kaminari

Rails: pagination with custom offset using Kaminari

梦想与她 提交于 2021-02-19 02:41:05
问题 I'm using Kaminari for pagination and under a certain situation need the first page to contain only 2 entries while each other to have 6. Thought this was achievable using padding() , but it doesn't seem to work like I'd expect (the documentation doesn't help much either): a = (1..20).to_a b = Kaminari.paginate_array(a).page(1).per(6).padding(2) => [3, 4, 5, 6, 7, 8] Any ideas on how to accomplish this? 回答1: this might help you: a = (1..20).to_a b = Kaminari.paginate_array(a).page(1).per(6)

kaminari undefined method 'page'

痴心易碎 提交于 2020-01-13 11:29:10
问题 I am trying to add Kaminari to my Rails app. I have included the gem and this is what my controller looks like: def index if params[:year] if params[:year].size > 0 @songs = Song.where("year like ?", params[:year]).page(params[:page]) elsif params[:artist].size > 0 @songs = Song.where("artist_name like ?", params[:artist]).page(params[:page]) elsif params[:song].size > 0 @songs = Song.where("title like ?", params[:song]).page(params[:page]) end else @songs = Song.first(10).page(params[:page])

Reverse pagination with kaminari?

梦想与她 提交于 2020-01-13 03:42:08
问题 I am using Kaminari 0.13.0 with RubyOnRails 3.2.8. Lets assume I have a default ordering of my elements by crated_at , I have 8 elements in my list {a, b, c, d, e, f, g, h} and I paginate them 3 per page. By default kaminari will create the following page links 1, 2, 3 linking to {h, g} , {f, e, d} , {c, b, a} . How do I make kaminari create the page links in reverse order? I want it to produce the links in reverse order 3, 2, 1 still linking to reverse ordered elements {h, g} , {f, e, d} ,

Unwanted form parameters being appended to pagination links

落爺英雄遲暮 提交于 2020-01-12 04:39:24
问题 I have a page which is used for searching through listings by submitting data using the supplied forms. The form parameters are submitted via ajax (post request), a new record is created in the searches table and then the listings are displayed (dynamically, on the same page the form is submitted from) via the show action for this record. The results have pagination links provided by kaminari like so: <%= paginate matches, :params => {:controller => 'searches', # I have to specify the id

Kaminari index from both data-remote and html messing with links

僤鯓⒐⒋嵵緔 提交于 2020-01-06 19:37:09
问题 I have an index view for a model(nested ) that never gets called from the model, but is rendered from a couple different models. One view can render the index with either JS or html. With JS is it in a #related div in the show view and a data-remote link. Another option uses the same controller action to render it only has html. All was fine until I added Kaminari paging. In the full page view, there was no #related div so paging didn't work. I broke out the guts into a partial and added a

Reverse pagination with kaminari

旧城冷巷雨未停 提交于 2020-01-01 07:53:25
问题 I want to create pagination for a messaging system in which the first page shown contains the oldest messages, with subsequent pages showing newer messages. For example, if normal pagination for {a,b,c,d,e,f,g,h,i} with 3 per page is: {a,b,c}, {d,e,f}, {g,h,i} Then reverse pagination would be: {g,h,i}, {d,e,f}, {a,b,c} I plan to prepend the pages so the result is the same as normal pagination, only starting from the last page. Is this possible with kaminari ? 回答1: There's a good example repo

Rails 3/Kaminari/JQuery - load more button: problem to display results (it loads the entire page layout and not only the partial layout)

痴心易碎 提交于 2019-12-30 02:28:11
问题 Begin with ajax and jquery combined with rails, I am trying to create a "load more" link in the bottom of my user index page. My user index page should display the 10 first users, then clicking the link it loads the next 10 users on the bottom of the user div, etc.. I use Kaminari for pagination. I started with the following code: User_controller.rb def index @users = User.page(params[:page]).per(10) end User/index.html.erb <div id="users"> <%= render :partial => @users %> </div> <%= link_to

Fetch objects upon pagination, rather than beforehand? (Rails + Kaminari)

爱⌒轻易说出口 提交于 2019-12-25 05:12:20
问题 So I have a search controller that returns a array of Object IDs (in this case 'Users'). Since the search results array can contain hundreds of IDs, I'd rather fetch the actual Objects themselves only when I need to send them to the view. In short, I want to use pagination to fetch the Objects themselves beforehand for each chunk of IDs (i.e. 1..10, 11..20, etc), rather than have the view logic fetch the Objects. I have no idea how to accomplish this. My controller code users = [1,3,456,23423

Kaminari Ajax paginate doesn't work

吃可爱长大的小学妹 提交于 2019-12-25 02:48:30
问题 I have below view and controller. Though remote: true is mentioned, kaminari calls my method using http (using page refresh). Is there anything i am missing to make my kaminari links ajaxable . In VIEWS: <div id="paginate"> <%= paginate @user, params: {slug: nil, pgsz: 20}, remote: true %> </div> In Controller: @user = Kaminari.paginate_array(@properties, total_count: @search_result.total_count).page(params[:page]).per(params[:pgsz] ||= 20) I will be responding to ajax in my controller, but

Is it possible to add anchor tags to kaminari URLs?

左心房为你撑大大i 提交于 2019-12-25 02:16:41
问题 Im using kaminari plugin for my pagination on Rails 3.1.3 I want my URL to have anchor tags at the ends as i will need that to select my jQuery tab For Ex: Current URL: http://mysite.com/users/index/2 What i want is: http://mysite.com/users/index/2#users How can i append this anchor tag into my URL? Can someone help me? 回答1: Just modify the templates at app/views/kaminari . For example, here is _page.html.haml : = link_to_unless page.current?, page, url, {:remote => remote, :rel => page.next?