Undefined method `paginate' for #<Class:0x567eb98> in Rails Tutorial

Hi,
I’m getting a undefined method `paginate’ for #Class:0x567eb98 even
though I have gem ‘will_paginate’ installed.
Inside the users_controller I have @users = User.paginate(page:
params[:page
])
so I believe I set everything up to be correct.
Can you figure out why the method’s undefined, despite installing the
gem?

On 24 October 2013 21:47, desbest [email protected] wrote:

Hi,
I’m getting a undefined method `paginate’ for #Class:0x567eb98 even though
I have gem ‘will_paginate’ installed.
Inside the users_controller I have @users = User.paginate(page:
params[:page])
so I believe I set everything up to be correct.
Can you figure out why the method’s undefined, despite installing the gem?

Which version of Rails are you using? If Rails 2 have you referenced
will_paginate in environment.rb, if rails 3 have you put it in your
Gemfile and run bundle install?

Colin

I’m using Rails 3 and I’ve ran bundle install and put it in my Gemfile.

On Thursday, October 24, 2013 11:11:33 PM UTC+1, desbest wrote:

I’m using Rails 3 and I’ve ran bundle install and put it in my Gemfile.

And you restarted the app after doing this?

Fred

On Friday, October 25, 2013 10:12:01 AM UTC+1, Colin L. wrote:

gem?

Which version of Rails are you using? If Rails 2 have you referenced
will_paginate in environment.rb, if rails 3 have you put it in your
Gemfile and run bundle install?

Gemfile.lock says

bootstrap-will_paginate (0.0.9)
will_paginate

will_paginate (3.0.4)

under GEM
and
will_paginate (= 3.0.4)
under dependencies.

I restarted the app using rails server and it didn’t work, but when I
restarted my computer it started to work.
Thanks for your help.

On 24 October 2013 23:11, tynamite [email protected] wrote:

I’m using Rails 3 and I’ve ran bundle install and put it in my Gemfile.

Please don’t top post, it makes it difficult to follow the thread.
Insert your reply inline. Thanks.

Hopefully you mean that you have put it in Gemfile and run bundle
install :slight_smile:
What does it show for paginate in Gemfile.lock?

Copy/paste the full error output here and the section of the
controller file containing the line giving the problem. Give us a
line number in the file so we can cross reference to the error.

Colin

I am a little late in discussion but I’ve the solution to the problem :slight_smile:

If you are using rails 4 then try this.

@users = User.all.paginate(page: params[:page]

Note that User.all will be an ActiveRelation on which paginate method
works.

If you are using rails 3 then try this.

@users = User.where(’’).paginate(page: params[:page])

The reason to use an empty where is because where will return the
ActiveRelation which is more efficient instead of loading an array using
User.all.

Note that User.all will return ActiveRelation in rails 4 and in rails 3
it
will return an Array.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs