单击链接在Rails中打开弹出窗口

我想点击“链接”打开一个弹出窗口,然后在那里显示一些数据并关闭它。

我正在使用’link_to’来创建’link’。 代码部分看起来像:

'aaa', :action=> 'xyz_links', ....... %> 

以前,在rails2.3.x中你可以这样做:

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

但现在在Rails3中,此选项已被弃用

另一个选择是使用Rails 3不引人注目的事件方式
委派这些链接:

如果要打开,请首先在link_to中添加属性“data-popup”
在一个新窗口中

然后,如果您使用的是jquery适配器,请在文档中添加application.js
准备好的处理

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

或者使用原型适配器,在文档中使用此代码
处理:

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

您可以在此处找到相同的讨论: http : //groups.google.com/group/rubyonrails-talk/browse_thread/thread/e1f02d9e0977071b/814d69e4d56cea65?show_docid=814d69e4d56cea65&utm_medium=twitter&pli=1

我没有尝试过这个,但在ruby docs中有这个:

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

请检查

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

Interesting Posts