I just want to use link_to
to open a popup. I tried something but it doesn't work:
<%= link_to 'Create a new company',
new_company_path,
:popup => ['create_company', 'height=600, width=600'] %> <br/>
Any idea?
Thanks!
Open Link in a Popup Window In order to open them in a new window, we add target="_blank" attribute to links. However to open the links in a separate popup window, we can make use of the onclick property and specifying a inline JavaScript code window.
Add this to your application.js.
$('a[data-popup]').on('click', function(e) { window.open($(this).attr('href')); e.preventDefault(); });
In the view, use something like:
= link_to( 'Create a new company', new_company_path, 'data-popup' => true )
<%= link_to 'Create a new company',
new_company_path,
:onclick=>"window.open(this.href,'create_company', 'height=600, width=600');return false;"
%>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With