title: Rails kaminari pagination for child table
body: <p>I have 2 classes: <code>Posts</code> and <code>Comments</code>, where posts <code>has_many :comments</code> and <code>comments belongs_to post</code>.</p>
  
  <p>Each of my posts has a show page with a list of comments and I would like to paginate the comments. With the current code I have, I'm showing a list of all the comments on all the pages. So, If i have 10 comments and I want to have 2 on each page, I get 5 pages with the original 10 comments on it. Could someone shed some light?</p>
  
  <p>My Code:</p>
  
  <pre><code>Posts controller:
  
  def show
    @post = Post.find(params[:id])
    @comments = @post.comments.page(params[:page]).per(3)
  
    respond_to do |format|
      format.html # show.html.erb
     format.json { render json: @post }
    end
  end
  
  
  "Show" views:
  
  &lt;%= paginate @comments %&gt;
  
  &lt;% @post.comments.each_with_index do |comments, index| %&gt;
      &lt;tr&gt;
      &lt;td&gt;&lt;%= index+1 %&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%= comment.date %&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%= comment.text %&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;% end %&gt;
  &lt;/table&gt;
  </code></pre>