Home Rails: will_paginate with multiple models
 I am having a really hard time figuring this one out and I'm hoping someone else has had to do something similar before: I have two models: class Device < ActiveRecord::Base has_many :pm_visits end class PmVisit < ActiveRecord::Base # attr_accessible :pm_date belongs_to :device end  I want to list the devices sorted by the date of the last PM (preventative maintenance) visit and also use will_paginate to limit the number of devices per page. The partial solution I have so far works in that it shows me the correct results, but doesn't work with will_paginate, and is do inefficient and ugly I am almost ashamed to show it, but here it is (in the devices_controller): @dev_list = [] dev_ids = PmVisit.joins(:device).where(devices.tech_id: 1).order("pm_date desc").map{|d| d.device_id}.uniq! dev_ids.each do |id| @dev_list << Device.find(id) end  Having required 'will_paginate/array' I hoped ... @dev_list.paginate(page: params[:page])  would paginate the array @dev_list but the will_paginate @dev_list line in the view gives me an error about total_pages method not found for Array object. I am also really unhappy with how I build @dev_list. If anyone can suggest a better way I would really appreciate it.