我有这个动作,
def email_student_report
@current_year = Time.new.year
@past_year = @current_year - 1
end
使用此链接,
<%= link_to 'Email', samplecardreport_path(format: :pdf), :class => 'btn btn-warning termact_btns' %>
我将此操作称为此操作,并使用wicked_pdf生成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
现在我的问题是生成的PDF文档是空白的。并且调试显示表单参数未被传递,因此查询将获取空白。我该如何解决这个问题?
答案 0 :(得分:0)
您需要使用以下提及的方法从link_to标签手动发送参数:
<%= link_to 'Email', samplecardreport_path(format: :pdf, param1: value1, param2: value2), :class => 'btn btn-warning termact_btns' %>
在你的情况下,这将是这些参数
<%= 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' %>
此行中的语法也不正确,缺少[在表格类params
@totalstudent = TermReport.group('form_class, term, year, studentid').where('form_class =? and term =? and year =?', params:form_class],params[:term],params[:year],)
正确
@totalstudent = TermReport.group('form_class, term, year, studentid').where('form_class = ? and term = ? and year = ?', params[:form_class],params[:term],params[:year],)
答案 1 :(得分:0)
如果您想将数据从控制器传递到 HTML 视图,您可以像这样在其中使用 locals
选项。
respond_to do |format|
format.html
format.pdf do
render pdf: "file_name", # Excluding ".pdf" extension.
template: "students/pdf.html.erb",
locals: { data: "hello world"}
end
end
然后像这样在views
中打印<%= data %>