Dhanu Gurung
Dhanu Gurung

Reputation: 8840

Open Pop-Up window in Rails on clicking link

I want to open a pop-up window on click of 'link', then show some data there and close it.

I am using 'link_to' to create 'link'. The part of code looks as:

<%= link_to 'Display Links', :controller=>'aaa', :action=> 'xyz_links', ....... %>

Upvotes: 1

Views: 13681

Answers (2)

alexkv
alexkv

Reputation: 5174

Previously, in rails2.3.x you could just do:

link_to "foo", foo_path(foo), :popup => true

But now in Rails3, this option has been deprecated

Another option is to use the Rails 3 unobtrusive way of event
delegating those links:

First add an attribute "data-popup" to your link_to if you want it to open
in a new window

Then if you are using the jquery adapter, add to application.js inside the document
ready handler:

$('a[data-popup]').live('click', function(e) { 
    window.open($(this).attr('href')); 
    e.preventDefault(); 
}); 

Or with the prototype adapter, use this code inside the document ready
handler:

document.on("click", "a[data-popup]", function(event, element) { 
    if (event.stopped) return; 
    window.open($(element).href); 
    event.stop(); 
}); 

You can find the same discussion here: http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/e1f02d9e0977071b/814d69e4d56cea65?show_docid=814d69e4d56cea65&utm_medium=twitter&pli=1

Upvotes: 3

dbKooper
dbKooper

Reputation: 1045

I haven't tried this but have this in ruby docs:

<%= link_to name, url, :popup => ['dialog name','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes'] %>

pls check at

http://apidock.com/rails/ActionView/Helpers/UrlHelper/link_to#29-Window-open-a-dialog-of-no-menu-no-status-have-scroll

Upvotes: 0

Related Questions