LoginSignup
6
3

More than 3 years have passed since last update.

NoMethodError: undefined method `paginate' for を解決する (Railsチュートリアル 10章)

Posted at

発生しているエラー

Railsチュートリアル10章 10.3.3 ページネーション

Gemfile
gem 'will_paginate',           '3.1.6'
gem 'bootstrap-will_paginate', '1.0.0'
$ bundle install

そしてチュートリアルの指示通りにコードを追記し、

$ rails test

を実行すると、

Error:
UsersIndexTest#test_index_including_pagination:
NoMethodError: undefined method `paginate' for #<Class:0x00007fb0253e5c60>
    app/controllers/users_controller.rb:6:in `index'
    test/integration/users_index_test.rb:14:in `block in <class:UsersIndexTest>'

というエラーが発生する。

対処法

$ spring stop

これを実行すると解決する。

参考:RAILS_ENV=test時のみ、paginateメソッドがundefinedになる

springとは

Spring は Rails アプリケーションの preloader(プリローダー)の gem です。(pre + load = 前もってロードしておく)

参考:RailsでSpringを導入して開発効率を上げる

今回はロードを勝手にしてくれるspringによる影響でエラーが発生していたようですね。
詳しく説明できる方は、コメントで補足していただけると幸いです。


役に立ったら是非LGTMボタンをポチッと押していただけると嬉しいです。
一緒に Rails学習 頑張りましょう!:raised_hand_tone1:

6
3
0

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
6
3