Reputation: 105
I've been trying to open multiple pdf's in new tabs automatically from my rails controller, but nothing has worked so far so I'm back to square one. If anyone could help, it would be much appreciated! Below is an example of what I'm trying to do.
id_array = [1,2,3]
id_array.each do |id|
// I want to open each of these three links in a new browser tab
http://localhost:3000/pdf/id.pdf
end
Cheers!
Upvotes: 3
Views: 3998
Reputation: 136
Can open files in new browser window using send_file method. Use :disposition => 'inline'
Eg: send_file "#{Rails.root}/pdf/id.pdf",:filename => 'id.pdf', :type => 'application/pdf', :disposition => 'inline'
Upvotes: 5
Reputation: 1202
you should respond with a javascript
file.
<% id_array.each do |id| %>
window.open('<%= "http://localhost:3000/pdf/#{id}.pdf" %>', '_blank');
<% end %>
Upvotes: 1