I have the following problem, I have a controller in which I make a query in which I get 10 different values each time I perform the query; but also at the same time I generate a pdf with wicked_pdf with the values with the values of the same query.
The problem I have is that when I render the data in my view, I want to generate a pdf with the same data, but when generating the pdf the data vary completely, that is, the query is executed again, How could this be avoided? ,
Controller
def index
@test = Test.find_by(name: params[:test])
@questions = TestQuestion.joins(:test).where(test_id:@test.id).order('RANDOM()').limit(10)
respond_to do |format|
format.html
format.pdf { render template: 'simulators/pdf', pdf: 'pdf'}
end
end
Agradesco in advance, any comment that can give me another approach to solve this problem