我添加了gem,重新启动了服务器。
在我的索引操作中,我有:
def index
@listings = Listing.paginate(page: params[:page])
end
我重新加载了我的观点。有用。
然后我放入分页链接:
<%= will_paginate @listings %>
我收到一个错误:
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'
由于某种原因,<%= will_paginate @listings %>
无法正常工作。
在错误控制台中,我可以看到错误源自:
Listing.paginate(page: params[:page])
完整的错误是:
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'
任何人都可以看到发生了什么?我完全糊涂了。是什么导致错误?
我使用的是过时的will_paginate
版本。
升级到3.1.7
后,问题就消失了。