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 8546355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:59:57+00:00 2026-06-11T12:59:57+00:00

Will paginate (3.0.3) doesn’t work with inherited resources (1.3.1). In my controller: protected def

  • 0

Will paginate (3.0.3) doesn’t work with inherited resources (1.3.1). In my controller:

protected
def collection
  @posts ||= end_of_association_chain.paginate(:page => params[:page])
end

I added require ‘will_paginate/array’ in my initializer, but this doesn’t fix the problem. How can i get working will paginate and inherited resources together? In my views i get error

undefined method `total_pages' for #<ActiveRecord::Relation:0x00000004312e38>
  • 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-11T12:59:58+00:00Added an answer on June 11, 2026 at 12:59 pm

    This is kind of a long shot, but I ran into this problem and it turns out it was CanCan, another gem I am using. This was one of the first things I stumbled on, so I figured it may help someone one day.

    Check out: https://github.com/ryanb/cancan/wiki/Inherited-Resources

    The call to load_and_authorize_resource loads the collection so the right side of the conditional assignment never gets run in the collection method. The fix that is described in the link above is to skip authorization for collection actions, and do the check explicitly in the collection method.

    skip_load_and_authorize_resource :only => :index
    
    protected
    
    def collection
      @posts ||= end_of_association_chain.accessible_by(current_ability).paginate(:page => params[:page])
    end
    

    I hope that helps someone.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make will_paginate's :order to work with this array: @posts = current_user.subscribed_tags.map(&:posts).flatten.paginate(:page
In my project model def incomplete @clients = current_user.clients.find_all_by_completed(false).paginate (:page => params[:page], :per_page =>
The following result sets work well with will_paginate: Members.all(:limit => 5).paginate(:page => params[:page]) Members.all(:conditions
Trying to understand the options for will_paginate's paginate method: :page — REQUIRED, but defaults
For some reasons, my will_paginate collection is stuck on page 2. I have the
I am trying to limit the number of elements returned with mislav's will paginate
I am Using will paginate 3.0.2 and Rails 3.1.0. The following code lives within
I have a collection of people that is paginated with will_paginate @people = Person.paginate
I've got a query which returns 30 rows. I'm writing code that will paginate
I'm having a big problem with will paginate. I have a query defined as

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.