I am looking to use Tire gem for pagination in Elastic Search in my ruby-script but params[:page] is detected as an undefined local variable:
require 'rubygems'
require 'tire'
require 'json'
require 'pp'
require 'fileutils'
require 'bigdecimal'
require 'bigdecimal/util'
require 'kaminari'
def SearchTesh
def self.aggregate_cost(account_id, start_date, end_date, options)
return nil if options[:tax_query] && options[:total_query] # both can't be true
if options[:tax_query] || options[:total_query] #strip day (keep only month) if either is true
start_date,end_date = start_date[0...-3], end_date[0...-3]
end
query_string = "PayerAccountId:\"#{account_id}\" AND UsageStartDate:[#{start_date} TO #{end_date}]"
opt = { :page => (params[:page] || 1), :size => 100 }
search_results = Tire.search '*', opt do
query { string "#{query_string}" }
from opt[:size].to_i * (opt[:page].to_i-1)
end
return nil if search_results.blank?
aggregated_results = parse_search_result(
search_results, {tax_query: options[:tax_query], total_query: options[:total_query]})
return aggregated_results
end
end
This is my function and at the line:
opt = { :page => (params[:page] || 1), :size => 100 }
the following error comes up:
tasks/test_search.rb:27:in
aggregate_cost': undefined local variable or methodparams' for SearchTest:Class (NameError)