Ask A Question

Notifications

You’re not receiving notifications from this thread.

Pagination with will_paginate Discussion

Hey,
That was a great screencast! Keep up the good work. I was just wondering if there's a way to limit users from accessing pages without any posts? Maybe by editing routes.rb?

Reply

You could probably do something like this in your controller:

@posts = Post.paginate(page: params[:page])
redirect_to root_path if @posts.empty?

Reply

If you are a noob like me and it doesn't work try adding ', :per_page => 1' as your controller pagination option.

I was working with seed data with only 10 customers in it so will_paginate was not rendering because the default 30 meant there was no reason to render it at all! I swore I had some bug but turns out it was just that.

Reply

Great idea! I've done that in the past when I wasn't sure why it wasn't rendering and that helped a lot. :)

Reply

I wish this was stated in the docs! Have just spent a hour trying to figure this out and it just turned out I didn't have enough data.... :(

Reply

Fantastic video. Thank you!

Reply

Doesn't work with 4.2

Reply

I have a multi page group member list list with a drop down selection box where one can edit a membership role, which is tied to an enum value.

It works, but in the case where one make edits on 2 or more separate pages and then updates, only the edit(s) on the current page are saved.

Is this the expected behavior? It obviously wipes out attributes when pagination occurs, but it does not seem intuitive to expect the user to update between switching pages.

... or maybe I'm just abusing will_paginates' purpose.

Reply

hello, please I tried using the will_paginate gem but am getting this error whenever I introduce the pagination link
link -- <%= will_paginate @ articles %>
error --- wrong number of arguments (given 2, expected 1)

please how do I go about this?

Reply

Ohre - you need to remove the space between @ and articles so it is just @articles

Reply

How to get submit button after pagination

Reply

Is it possible to hide submit button and show after pagination pages

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 87,563+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.