I have a hotel model and on our homepage we have a nominated section which should show the last 10 hotels in a sidebar paginated to 5 per page. I have read some documentation regarding will_paginate and realise there is no decent way to limit the number of objects sent to will_paginate, so a call for limit won’t achieve anything and thus the sidebar shows all of the hotels, paginated 5 per page and the code below doesn’t work as intended.
@nominations = Hotel.where(winner: false).limit(10).paginate(page: params[:page], per_page: 5)
I was wondering if there is a way to limit the number of pages shown with will paginate? so even if there are 5 pages each with 5 hotels on them, it will only show 2 pages. So effectively limiting the number of items shown. I have looked at inner and outer window parameters but I dont think these will help for this situation. Or if anyone has any other method for achieving this I am all ears.
Oh and yes, we have to paginate the nominations as the sidebar will run on far past the other content on the page which won’t look great I’m afraid.
if you need more code just shout.
Thanks to the question Limit number of pages in will_paginate all one has to do is pass the total_entries parameter into the paginate function. So my code looks like this: