Rails - 在 Twitter Bootstrap 弹出窗口中渲染部分 [英] Rails - Render partial inside Twitter Bootstrap popover

查看:62
本文介绍了Rails - 在 Twitter Bootstrap 弹出窗口中渲染部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Twitter Bootstrap 弹出框来显示用户头像和电子邮件地址,以便日后添加更多详细信息.

I want to use a Twitter Bootstrap popover to display a user avatar and email address, with the possibility of adding in more details at a later date.

我在获取部分内容以在链接的内容字段中呈现时遇到问题.视图代码如下(在 HAML 中).

I am having an issue getting the partial to render inside the content field of the link. The view code is below (in HAML).

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

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

Currently, this will only produce the content code as a string.

有没有办法做到这一点,以便将部分插入而不是将代码作为字符串插入?

Is there a way to do this so the partial will be inserted instead of the code as a string?

推荐答案

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

You want rails to actually evaluate the content of the string and not just show the string. The easiest way to do that would be:

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

这应该将渲染语句传递给 rails 并按预期渲染您的部分.

That should pass the render statement to rails and render your partial as expected.

这篇关于Rails - 在 Twitter Bootstrap 弹出窗口中渲染部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆