I'm getting bunch of XML datas from an external API. It gives me all data paginated which has 20 records per page.It also gives me total record count for each document.I'm getting XML -in fact plist data- with \[code\]Typhoeus\[/code\] gem, I'm converting it with \[code\]Plist\[/code\] gem and I'm inserting them to database.Issue is; I can insert first 20 records -which means the first page- easily. But how can I calculate how many pages per document has and how can I dynamically make queries for other pages?Here is my controller and actions. It works for first page, but not other pages.\[code\]class Admin::VideosController < ApplicationControllerdef index @videos = Video.where(program_id: params[_id]) @program = Program.find(params[_id]) if params[:cmd]=="get_videos_from_outer" @page=1 @fetch = Typhoeus::Request.post("URL", arams => {:commandtype=>"getprogramepisodes", :feedtype=>"plist",:id=>@program.kid, age=>@page}) @plist = Plist:arse_xml(@fetch.body.force_encoding 'utf-8') import_outer_videos(@plist) redirect_to :action=>"index", _id=>params[_id] end endend\[/code\]And here I'm instering data:\[code\]privatedef import_outer_videos(plist) @total_count = plist.second.first['totalCount'] if !plist.blank? plist.second.each_with_index do |t, i| if @page==1 if i > 0 @new = Video.createthumb_path=>t['tnPath'], :vid=>t['id'], :title=>t['title'], :type=>t['type'], :kid=>@program.kid, rogram_id=>@program.id) end else @new = Video.createthumb_path=>t['tnPath'], :vid=>t['id'], :title=>t['title'], :type=>t['type'], :kid=>@program.kid, rogram_id=>@program.id) end end @page = @page + 1 unless @page >= @total_count/20 rescue 0 puts "############################### #{@page} - #{@total_count} ###############################" if @new.errors.blank? flash[:notice]="Videos has been uploaded." else flash[:notice]="No new video." end endend\[/code\]PS: I'm using MongoDB and Mongoid.Thanks in advance for help.