I have this action,
def email_student_report
@current_year = Time.new.year
@past_year = @current_year - 1
end
Using this link to,
<%= link_to 'Email', samplecardreport_path(format: :pdf), :class => 'btn btn-warning termact_btns' %>
I calls this this action and generate a PDF document with wicked_pdf
def sample_card_report
@subjects = Subject.all
@properties = Property.first
@studentid = Student.where('studentid = ?', params[:email_search_stuent_id]).last!
#@studentid = Student.where('studentid = ?', 'EkGSS-181').last!
@studentresults = TermReport.where('studentid =? and term =? and form_class =? and year =?', params[:email_search_stuent_id], params[:term], params[:form_class], params[:year])
@totalstudent = TermReport.group('form_class, term, year, studentid').where('form_class =? and term =? and year =?', params:form_class],params[:term],params[:year],)
respond_to do |format|
format.html
format.pdf do
render pdf: 'student_report_card',
template: "term_reports/sample_card_report.pdf.erb"
end
end
end
Now my problem is the generated PDF document is blank. And debugging shows that the form params are not being passed so the query is fetching blank. How can I resolve this?
You will need to send the params manually from the link_to tag using the below mentioned:
<%= link_to 'Email', samplecardreport_path(format: :pdf, param1: value1, param2: value2), :class => 'btn btn-warning termact_btns' %>
In your case it would be these params
<%= link_to 'Email', samplecardreport_path(format: :pdf, email_search_stuent_id: value1, term: value2,form_class: value3, year: value4), :class => 'btn btn-warning termact_btns' %>
Also the syntax in this line is also not correct, it is missing [ in form class params
@totalstudent = TermReport.group('form_class, term, year, studentid').where('form_class =? and term =? and year =?', params:form_class],params[:term],params[:year],)
Correct
@totalstudent = TermReport.group('form_class, term, year, studentid').where('form_class = ? and term = ? and year = ?', params[:form_class],params[:term],params[:year],)