Reputation: 181
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
Upvotes: 12
Views: 6661
Reputation: 770
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
Upvotes: 25
Reputation: 3662
If you want to open the window conditionally, depending upon successful submission of your form you might:
remote: true
on your formformat.js { render :show, status: :ok }
to your controllershow.js
file that runs window.open
per the reply by VishalThis is one way you can get started with AJAX forms
Upvotes: 1
Reputation: 799
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>
Upvotes: 3
Reputation: 7361
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
Upvotes: 2