3

I am using Ruby on Rails 3.2.1 and Kaminari gem 0.13.0.

I have added gem 'kaminari' in my gemfile, then ran Bundle install.

In controller I have @posts = Post.order("name").page(params[:page])

In view:

<%= paginate @posts%>
        <% @posts.each{|posts| %>
            <h1 class="title"><%= link_to posts.title, posts %></h1>
                <p class="byline">Raksts izveidots: <%= posts.created_at.utc.strftime("%d.%m.%Y") %></p>
                <div class="entry">
                    <p><%= posts.content %></p>
                </div>
            <p class="meta"><a href="#" class="more">Read More</a> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <a href="#" class="comments">Comments</a> (33)</p>           
        <% } %>
        <%= paginate @posts%>

But in result I have undefined method 'paginate' for #<#<Class:0x3cf68b8>:0x2ab92b0>.

Anyone could help me?

 class PostsController < ApplicationController
    # GET /posts
    # GET /posts.json
    def index
      @posts = Post.order(:name).page(params[:page]).per(2)
      @posts = Post.order('posts.id DESC')


      respond_to do |format|
        format.html  #index.html.erb
        format.json { render json: @posts }
      end
    end
fl00r
  • 82,987
  • 33
  • 217
  • 237
RydelHouse
  • 235
  • 1
  • 8
  • 19

2 Answers2

4
def index
  @posts = Post.order(:name).page(params[:page]).per(2)

  respond_to do |format|
    format.html  #index.html.erb
    format.json { render json: @posts }
  end
end
fl00r
  • 82,987
  • 33
  • 217
  • 237
1

I think you can do:

@posts = Post.order(:name).page(params[:page]).per(2), order: 'post_id desc',
                                                         per_page: 10

Hope this helps.

Jax
  • 1,839
  • 3
  • 18
  • 30