Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- YouTubeModel::SingletonMethods.class_eval do
- include WillPaginate::Finders::Base
- protected
- def wp_query(options, pager, args)
- # dup options and set limit
- args << options.merge(:max_results => pager.per_page)
- # carefully add start_index (YouTube goes nuts if it's zero)
- args.last[:start_index] = pager.offset if pager.offset > 0
- # perform the search
- youtube = send(:find, *args)
- # populate the collection with videos
- pager.replace youtube.videos
- # keep track of total results
- unless pager.total_entries
- pager.total_entries = youtube.totalResults.to_i
- end
- end
- end
Add Comment
Please, Sign In to add comment