在导轨模态中渲染部分

时间:2012-02-22 20:48:55

标签: javascript ruby-on-rails

我遇到了在模态窗口中渲染局部的问题。我已经尝试过简单模态和原型窗口。我基本上试图在模态弹出窗口中渲染部分内容。现在看来是这样的:

<%=link_to_function("Share This!", "win = new Window({title: \"Share This\", width:200, height:150, destroyOnClose: true, recenterAuto:false});
win.getContent().update("+escape_javascript(render :partial => 'groups/show')+");
win.showCenter();
")%>

我尝试了多种组合,如何放置escape_javascript位以及在简单模态下尝试这个。

任何帮助都会非常感激。

1 个答案:

答案 0 :(得分:5)

我认为更容易渲染页面上的部分(隐藏),然后在按下按钮时使用setContent将其捕获到窗口中。这意味着你可以将更多的j放在页面之外,这也会更好。

在视图中:

<div id="groups_show" style="display:none">
  <%= render :partial => 'groups/show' %> 
</div>

<%= link_to_function("Share This!", "show_group_popup()") %>

在application.js(或其他包含的js文件)中:

function show_group_popup() {
  $('groups_show').show();
  win = new Window({title: "Share This", width:200, height:150, destroyOnClose: true, recenterAuto:false});
  win.setContent('groups_show',true,true);
  win.show();
}