undefined method `paginate' for
kaminari, ruby-on-rails
Solution
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
Problem
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> <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 ```