Onsubmit of a form, open up on a new tab

2.7k views Asked by At

On selection of batch. I render a partial(displays students), after selection of students, I should generate a pdf in a new tab.

_batch_students.html.erb

<% form_for :custom_reports, :url=>{:action=>"custom_report_pdf"} do |f| %>
#code
<%= f.submit "► #{t('pdf_report')}", :class=>"submit-button"%>

It currently works fine, but how to get the pdf in new tab? Need to use Javascript?

And the url currently with pdf looks like

http://localhost:3000/design_custom_reports/custom_report_pdf

On reload in chrome alerts me to resend data but in firefox it doesn't prompt and results in error.

Rails 2, Ubuntu 12.04

1

There are 1 answers

0
Baldrick On BEST ANSWER

Use the attribute target="_blank" on the html form:

<% form_for :custom_reports, :url=>{:action=>"custom_report_pdf"}, :html => {:target => '_blank'} do |f| %>

It will generate the following HTML

<form target="_blank" ... >