Rails – 在Twitter Bootstrap popover中部分渲染

我想使用Twitter Bootstrap popover来显示用户头像和电子邮件地址,可以在以后添加更多详细信息。

我有一个问题是在链接的内容字段内部分渲染。 视图代码如下(在HAML中)。

%span.comment-username =link_to comment.user_name, "#", "title" => comment.user_name, "data-content" => "=render 'users/name_popover'", class: "comment-user-name" 

目前,这只会将内容代码生成为字符串。

有没有办法这样做,所以部分将插入而不是作为字符串的代码?

您希望rails实际评估字符串的内容,而不仅仅是显示字符串。 最简单的方法是:

 %span.comment-username =link_to comment.user_name, "#", "title" => comment.user_name, "data-content" => "#{render 'users/name_popover'}", class: "comment-user-name" 

这应该将render语句传递给rails并按预期渲染部分。

感谢jrc的答案 – 它帮助我找到了解决方案。

我的解决方案可能对像我这样的其他非HAML人有用:

 `<%= link_to('Service History' , '#', :class => "popover-history", :rel => "popover", :"data-placement" => "bottom", :title => "Service History", :"data-content" => "#{render 'services/service_history'}") %>` 

 `$(function () { $('.popover-history').popover({ html : true }); });`