Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open a new window on click submit in rails

Hello i want to open new window on click of submit button using ruby on rails, Here is my code

<div class="actions">
        <%= f.button :submit,:class => 'btn btn-md btn-success' do %>
          <i class='fa fa fa-plus'></i> Create New Window
        <% end %>
</div>

i have tried :target => "_blank" in submit, but it doesnt work, please help me

like image 458
Hemanthkumar Naik Avatar asked Jul 14 '16 05:07

Hemanthkumar Naik


4 Answers

use formtarget="_blank".

<%= form_for @my_obj do |f|

<div class="actions">
    <%= f.button :submit,:class => 'btn btn-md btn-success', :formtarget => "_blank" do %>
      <i class='fa fa fa-plus'></i> Create New Window
    <% end %>
</div>

This link will help you http://www.w3schools.com/tags/att_button_formtarget.asp

like image 140
sohail khalil Avatar answered Oct 09 '22 12:10

sohail khalil


You have to pass target="_blank" in your form

for an example

<form action="..." ...
onsubmit="window.open('google.html', '_blank', 'scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,status=no');return true;">

Try this one

like image 36
Vishal Avatar answered Oct 09 '22 14:10

Vishal


Did you try target sending target as _blank parameter in form_for not in submit button.

<%= form_for @my_obj, html: { target: "_blank" } do |f|

<div class="actions">
        <%= f.button :submit,:class => 'btn btn-md btn-success' do %>
          <i class='fa fa fa-plus'></i> Create New Window
        <% end %>
</div>
like image 2
rohin-arka Avatar answered Oct 09 '22 13:10

rohin-arka


If you want to open the window conditionally, depending upon successful submission of your form you might:

  • Set remote: true on your form
  • Add a format.js { render :show, status: :ok } to your controller
  • Add a show.js file that runs window.open per the reply by Vishal

This is one way you can get started with AJAX forms

like image 1
Jay Dorsey Avatar answered Oct 09 '22 13:10

Jay Dorsey