Will_paginate undefined method 'per'

I recently installed the will_paginate gem on my development blog and am having problems. I added it to my gemfile:

gem 'will_paginate'

then passed it to the message controller:

def index
  @posts = Post.paginate(:per_page => 5, :page => params[:page], :order => 'created_at DESC')

  respond_to do |format|
    format.html # index.html.erb
    format.json { render json: @posts }
    format.atom
  end
end

and finally to the view:

 <div id="post" style="background-color: gray; border-radius: 20px; border-bottom: solid    black 2px; padding-bottom: 40px; padding-top: 40px; margin: auto;">
    <%= post.content.html_safe %>
 </div>
<br />
<div style="padding-bottom: 40px; background-color: brown;">
    <li>Posted:&nbsp;&nbsp;<%= post.created_at.to_formatted_s(:long) %></li>
    <li>Author:&nbsp;&nbsp;<%= post.author_name %></li>
    <li>Comments:&nbsp;&nbsp;<%= post.comments.count %></li>
</div>
<br />
<br />

<%= will_paginate @posts %>

The index page is working fine. Currently, it is not paginated, because I do not have enough posts created in the development environment (I was going to create them through the admin panel, I ran into this). It also works great in the admin panel (using active_admin). This is only when I click on "messages" (or any other link) in the admin panel to create a new entry, I get the following error:

NoMethodError in Admin::PostsController#index
undefined method `per' for #       <ActiveRecord::Relation::ActiveRecord_Relation_Post:0x5b37d30>

I am not sure how to proceed further, and appreciate any help. Sorry for the simple question.

+4
1

, ActiveAdmin Kaminari , will_paginate.

. : https://github.com/gregbell/active_admin/blob/47aa68d33da02c2c05cf1769402aac3df0ad02c7/docs/0-installation.md

# config/initializers/kaminari.rb
Kaminari.configure do |config|
  config.page_method_name = :per_page_kaminari
end
+18

All Articles