如何让 options_for_select 兑现标签

发布于 2024-11-04 06:54:44 字数 694 浏览 2 评论 0原文

我试图根据其层次结构级别缩进选择的类别列表中的选项,例如 Category Subcategory  Subsubcategory代码>.

我尝试过: <% options = options_for_select @categories.map{|c| [("&nbsp;" * c.level) + c.name, c.id]} %>, 但这会呈现为 &nsbp;Subcategory&nbsp;&nbsp;Subsubcategory

我尝试过: <% options = options_for_select @categories.map{|c| [(" " * c.level) + c.name, c.id]} %>, 但这会忽略空格并呈现为 SubcategorySubsubcategory

作为测试,我尝试了 <%= (" " * 3) + "hello" %>,这呈现了我期望的效果:  ;  你好

有谁知道如何获得我正在寻找的结果?

I'm trying to indent options in a select list of categories based upon their hierarchical level, e.g. Category,  Subcategory,   Subsubcategory.

I've tried:
<% options = options_for_select @categories.map{|c| [(" " * c.level) + c.name, c.id]} %>,
but this renders as &nsbp;Subcategory and   Subsubcategory.

I've tried:
<% options = options_for_select @categories.map{|c| [(" " * c.level) + c.name, c.id]} %>,
but this ignores the spaces and renders as Subcategory and Subsubcategory.

As a test, I tried <%= (" " * 3) + "hello" %>, and this renders how I'd expect it to:    hello.

Does anyone know how to get the results I'm looking for?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暮凉 2024-11-11 06:54:45

尝试使用 ((" " * c.level) + c.name).html_safe。问题出在使用 html_escapeoptions_for_select 辅助方法中,该方法会转义您的   实体。添加 html_safe 将允许从 options_for_select 帮助器调用 html_escape 方法来避免转义空格。

Try using ((" " * c.level) + c.name).html_safe. The problem is in the options_for_select helper method using html_escape, which escapes your   entities. Adding the html_safe will allow the html_escape method called from the options_for_select helper to avoid escaping the spaces.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文