Reputation: 3618
I've added the gem, restarted the server.
In my index action I have:
def index
@listings = Listing.paginate(page: params[:page])
end
I reload my view. It works.
I then drop in the pagination links:
<%= will_paginate @listings %>
I get an error:
ActionView::Template::Error (wrong number of arguments (given 0, expected 1)):
12:
13: <%= render 'shared/subscribe' %>
14:
15: <%= will_paginate @listings %>
16: <div class="content listings">
17: <h1>Latest<span class="meta">updated <%= time_ago_in_words(@listings.first.updated_at) %> ago</span></h1>
18: <% @listings.each do |listing| %>
app/views/listings/index.html.erb:15:in `_app_views_listings_index_html_erb___4466103937708592830_70228331044140'
For some reason <%= will_paginate @listings %>
isn't working.
In the error console, I can see that the error originates from:
Listing.paginate(page: params[:page])
The full error is:
ArgumentError: wrong number of arguments (given 0, expected 1)
from /Users/guff/.rvm/gems/ruby-2.6.2/gems/will_paginate-3.0.12/lib/will_paginate/active_record.rb:149:in `select_for_count'
from /Users/guff/.rvm/gems/ruby-2.6.2/gems/activerecord-5.2.3/lib/active_record/relation/calculations.rb:225:in `perform_calculation'
from /Users/guff/.rvm/gems/ruby-2.6.2/gems/activerecord-5.2.3/lib/active_record/relation/calculations.rb:145:in `calculate'
from /Users/guff/.rvm/gems/ruby-2.6.2/gems/activerecord-5.2.3/lib/active_record/relation/calculations.rb:52:in `count'
from /Users/guff/.rvm/gems/ruby-2.6.2/gems/will_paginate-3.0.12/lib/will_paginate/active_record.rb:97:in `count'
from /Users/guff/.rvm/gems/ruby-2.6.2/gems/will_paginate-3.0.12/lib/will_paginate/active_record.rb:95:in `count'
from /Users/guff/.rvm/gems/ruby-2.6.2/gems/will_paginate-3.0.12/lib/will_paginate/active_record.rb:79:in `total_entries'
from /Users/guff/.rvm/gems/ruby-2.6.2/gems/will_paginate-3.0.12/lib/will_paginate/active_record.rb:135:in `block in to_a'
from /Users/guff/.rvm/gems/ruby-2.6.2/gems/will_paginate-3.0.12/lib/will_paginate/collection.rb:96:in `create'
from /Users/guff/.rvm/gems/ruby-2.6.2/gems/will_paginate-3.0.12/lib/will_paginate/active_record.rb:133:in `to_a'
from /Users/guff/.rvm/gems/ruby-2.6.2/gems/activerecord-5.2.3/lib/active_record/relation/finder_methods.rb:512:in `find_take_with_limit'
from /Users/guff/.rvm/gems/ruby-2.6.2/gems/activerecord-5.2.3/lib/active_record/relation/finder_methods.rb:103:in `take'
from /Users/guff/.rvm/gems/ruby-2.6.2/gems/activerecord-5.2.3/lib/active_record/relation.rb:513:in `inspect'
Can anyone see what is going on? I'm completely confused. What is causing the error?
Upvotes: 2
Views: 1528
Reputation: 311
Updating the will_paginate
gem to 3.1.7 for Rails 5.2 removed that error mentioned.
Upvotes: 1
Reputation: 3618
I was using an outdated version of will_paginate
.
The problem went away after upgrading to 3.1.7
.
Upvotes: 3