[Rails] Re: undefined method `paginate' for # in Rails Tutorial
I am a little late in discussion but I've the solution to the problem :)
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
.
On Friday, October 25, 2013 1:47:19 AM UTC+5, desbest 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?
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/2390d463-501b-4ed3-8c26-2448d2b05544%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home