How to use _blank or _new in Rails
I think it's like this
<%= link_to image_tag('img.png'), 'http://www.website.com', target: '_blank' %>
See http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to
How to automatically add _blank to anchor links in Ruby on Rails
You can achieve this using JavaScript:
$("a").click(function() {
if (!/^#/.test($(this).attr('href'))) {
window.open(this.href, '_blank');
return false;
}
});
This code will open all the anchors with the target
attribute set to _blank
.
Why does link_to method post, target blank not open in a new tab?
It appears to be fixed in https://github.com/rails/jquery-ujs/commit/888be8adcb7d609f442b3883dc722.
"jquery-ujs" is distributed as part of the "jquery-rails" gem.
Try to bundle update jquery-rails
itself to the latest version (which is 2.1.1).
Rails if empty, use other value
Override the getter in your model:
def billing_email
super.blank? ? email : super
end
But you'd rather use another method name, or keep the same name but in a decorator for instance.
Using target: _blank on button_tag
To submit a form to new window, use target
attribute on <form>
element:
<form action="" target="_blank">
Rails link_to and onClick with target=_blank does not work together
Please try to use window.open()
<script>
var trackOutboundLink = function(url) {
ga('send', 'event', 'outbound', 'click', url, {'hitCallback':
function () {
window.open(url);
}
});
}
</script>
Please see this link
Target Blank not opening the link in a new tab
Yes, your javascript looks to be the culprit. So instead of window.location.assign
, try using window.open
as follows:
window.open("http://localhost:3000/patients?provider="+provider_id+"&"+"therapeutic_class="+thera_class, '_blank');
Open a new window on click submit in rails
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
Related Topics
Does Ruby Have Syntax for Safe Navigation Operator of Nil Values, Like in Groovy
Version Sort (With Alphas, Betas, etc.) in Ruby
Sharing an Enumerator Across Threads
Call Ruby Script from Powershell
"No Routes Matches" When Using Current_Page in Rails 3
Async Requests Using Sinatra Streaming API
Ruby Pipes: How to Tie the Output of Two Subprocesses Together
Authlogic and Multiple Sessions for the Same User
Rails 4.1 Activerecord::Relation Is No More Like Array
How to Get Http Headers Before Downloading with Ruby's Openuri
Encryption-Decryption in Rails
How to Preload Concerns in a Rails Initializer Using Rails 6/Zeitwerk