How to use the link_to helper to open a popup?

Amokrane Chentir picture Amokrane Chentir · Mar 6, 2011 · Viewed 19.2k times · Source

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!

Answer

Mark Swardstrom picture Mark Swardstrom · Jan 12, 2012

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 )