Ask A Question

Notifications

You’re not receiving notifications from this thread.

Will_paginate problems

kaine Wright asked in Rails
Hi ive been building a new web app based on michael hartl tutorial but im having problems with the will_paginate tests. 

When i load all my users it will display every one of them so of course i add gem will_paginate to gemfile and 
User.paginate(:page => params[:page], :per_page => 30)

 to my def index.  inside my index.html.erb i have 
<%= will_paginate %> 

This all works great i load the server and start to browse through my users page by page. Im not sure how its working though becuase in the tests i have this 

require 'test_helper'

class UsersIndexTest < ActionDispatch::IntegrationTest
  def setup
    @user = users(:michael)
  end

  test "index including pagination" do
    log_in_as(@user)
    get users_path
    puts @response.body
    assert 'users/index'
    assert_select 'div.paginate' #if i remove .paginate assert select test passes. but can not find the paginate code.
    User.paginate(page: 1, per_page: 10).each do |user|
      assert_select 'a[href=?]', user_path(user), text: user.username
    end
  end
end

if on the index.html.erb i add this instead 
<div class="paginate"> <%= will_paginate %> </div>

@response.body shows this <div class="paginate">  </div> but there should be another div paginate inside the written one. and if i remove the erb all together leaving the written div things still work. So im lost as to what is happening 

Reply

Thank you for such an excellent post and review; I am blown away! Continue to publish similar content.

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,946+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.