Hi everybody I'm trying to use wicked pdf in rails. Get a pdf based on the object generated by the query, @questions
When downloading the pdf, the query data is lost. when I visit "/simulators.pdf" it shows me the following error in console
Started GET "/simulators.pdf" for 127.0.0.1 at 2018-11-01 12:38:19 -0500
Processing by SimulatorsController#index as PDF
Test Load (0.2ms) SELECT "tests".* FROM "tests" WHERE "tests"."name" IS NULL LIMIT $1 [["LIMIT", 1]]
CACHE Test Load (0.0ms) SELECT "tests".* FROM "tests" WHERE "tests"."name" IS NULL LIMIT $1 [["LIMIT", 1]]
Completed 500 Internal Server Error in 3ms (ActiveRecord: 0.2ms)
NoMethodError (undefined method `id' for nil:NilClass):
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
URL:
http://localhost:3000/simulators?test=biology
This is url of index view
Can you help me? Many thanks