Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined method `paginate' for

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
like image 413
RydelHouse Avatar asked Aug 04 '26 06:08

RydelHouse


1 Answers

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
like image 59
fl00r Avatar answered Aug 05 '26 23:08

fl00r



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!