I have a huge database and I want to reduce the query response time by using will_paginate.
I am trying to group my entries by a column and then use the will_paginate to put results into different pages.
I try to do this
@list= Persons.find_by_sql(select).group_by {|t| t.gender}
@detail= @list.paginate(:page => params[:page], :per_page => 30)
but it gives me this error:(undefined method paginate for<Hash:0x3de9930>):
Anyone know how to solve this problem?
[Additional information]
Someone on the will_paginate forum says this:
Because you already have to load all the users from the database in order to perform the group_by, my suggestion is simply to forget about pagination and output them as-is.
Does it mean there is no point to use GROUP_BY while using will_paginate?
@paginated_lists = Persons.find_by_sql(select).paginate(:page => params[:page], :per_page => 30)
@details = @paginated_lists.to_a.group_by { |t| t.gender }
Try this it should work it worked for me :) use @paginated_lists for paginating.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With