Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8964881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:41:15+00:00 2026-06-15T16:41:15+00:00

I have a hotel model and on our homepage we have a nominated section

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:41:16+00:00Added an answer on June 15, 2026 at 4:41 pm

    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:

    @nominations = Hotel.where(winner: false).paginate(page: params[:page], per_page: 5, total_entries: 10)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Afternoon all, I have a Month model which has many hotels. A hotel belongs_to
I have created an application which allows the user to find the nearest hotels.
If I have an object 'Hotel' which has a few set properties and I
I have following code: hotels = models.Hotel.objects.filter( wed=True, county=hotel_main.county.id, subscriptions__end_date__gte=datetime.date.today(), subscriptions__enquiry_count__lte=F('subscriptions__tier__enquiry_limit'), ).filter(Q(x=TRUE|Q(y=True)).distinct() And i
I have a country with many hotels, how can i get all countries which
I have a model : class Hotel < ActiveRecord::Base has_many :hotel_comments end In my
I have a nested list, something like this: List<Hotel> Hotels; public class Hotel {
I have a model : class HotelTheme < ActiveRecord::Base has_many :hotels end I want
I have many different arrays with dictionaries of hotels in a data model class.
I have a 'Complex' model which hasMany Unit. My model associations are correct, everything

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.