Guest User

Untitled

a guest
Feb 21st, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. YouTubeModel::SingletonMethods.class_eval do
  2. include WillPaginate::Finders::Base
  3.  
  4. protected
  5.  
  6. def wp_query(options, pager, args)
  7. # dup options and set limit
  8. args << options.merge(:max_results => pager.per_page)
  9. # carefully add start_index (YouTube goes nuts if it's zero)
  10. args.last[:start_index] = pager.offset if pager.offset > 0
  11. # perform the search
  12. youtube = send(:find, *args)
  13. # populate the collection with videos
  14. pager.replace youtube.videos
  15. # keep track of total results
  16. unless pager.total_entries
  17. pager.total_entries = youtube.totalResults.to_i
  18. end
  19. end
  20. end
Add Comment
Please, Sign In to add comment