LoginSignup
38
14

More than 3 years have passed since last update.

Paginate導入時のエラー wrong number of arguments (given 0, expected 1)

Posted at

初心者がRails tutorial第10章でPaginate導入後にぶつかったエラーについてお話します。

gemfileに以下のように入力。rails bundleでインストール。

source 'https://rubygems.org'
.
.
gem 'will_paginate',           '3.1.6'
gem 'bootstrap-will_paginate', '1.0.0'
.
.

その後、以下のようにindexファイルを作成、記述しました。

app/view/users/index.html.erb

<% provide(:title, 'All users') %>
<h1>All users</h1>

<%= will_paginate %>

<ul class="users">
  <% @users.each do |user| %>
    <li>
      <%= gravatar_for user, size: 50 %>
      <%= link_to user.name, user %>
    </li>
  <% end %>
</ul>

<%= will_paginate %>

記載後、tutorialの指示通りテストをすると、以下のように引数不足というエラーが出現。

ERROR["test_index_as_non-admin", #<Minitest::Reporters::Suite:0x000055a04b425c20 @name="UsersIndexTest">, 4.376546631000004]
 test_index_as_non-admin#UsersIndexTest (4.38s)
ActionView::Template::Error:         ActionView::Template::Error: wrong number of arguments (given 0, expected 1)
            app/views/users/index.html.erb:4:in `_app_views_users_index_html_erb___422248519655019949_47073486417860'
            test/integration/users_index_test.rb:29:in `block in <class:UsersIndexTest>'

初心者なりに悩みに悩みましたが、結局は解決できました。
実はこれ、gem自体のバグでした。ですのでgemのバージョンを3.1.6から3.1.7に変えて、rails bundle installとしてあげれば解決します。

source 'https://rubygems.org'
.
.
gem 'will_paginate',           '3.1.7'
gem 'bootstrap-will_paginate', '1.0.0'
.
.

2019年5月1日時点でRails tutorialの記載が変更されていないので、私自身を含め、ここで躓く方が多いのではないかと思い、記事を作成させていただきました。

ソースhttps://github.com/mislav/will_paginate/issues/589

38
14
5

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
38
14