I am trying to use pagy gem but I am getting no method error.
In my controller, I previously have
def index
@hires = [*current_user.student_hires.order('created_at desc')]
current_user.groups.includes(:group_hires).each do |group|
@hires.push(*group.group_hires.order('created_at desc'))
end
@hires = @hires.uniq(&:id)
end
but since I want to use Pagy, I changed it to
def index
@pagy, @hires = pagy([*current_user.student_hires.order('created_at desc')])
current_user.groups.includes(:group_hires).each do |group|
@hires.push(*group.group_hires.order('created_at desc'))
end
@hires = @hires.uniq(&:id)
end
and in my view, I have
<%== render partial: 'pagy/nav', locals: {pagy: @pagy} %>
But I am getting
undefined method `offset' for [#<Hire id: 12, grade: "Grade 1"
I am using pagy in another simpler controller and it works well but I can't get it to work on this controller index.
I was able to fix it using pagy_array
So I did
@pagy, @hires = pagy_array([*current_user.student_hires.order('created_at desc')])
and also added require 'pagy/extras/array'
to the config/initializers
More instruction about it is here https://ddnexus.github.io/pagy/extras/array#gsc.tab=0
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.