如何让 options_for_select 兑现标签
我试图根据其层次结构级别缩进选择的类别列表中的选项,例如 Category
、 Subcategory
、 Subsubcategory
代码>.
我尝试过: <% options = options_for_select @categories.map{|c| [(" " * c.level) + c.name, c.id]} %>
, 但这会呈现为 &nsbp;Subcategory
和 Subsubcategory
。
我尝试过: <% options = options_for_select @categories.map{|c| [(" " * c.level) + c.name, c.id]} %>
, 但这会忽略空格并呈现为 Subcategory
和 Subsubcategory
。
作为测试,我尝试了 <%= (" " * 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用
实体。添加
((" " * c.level) + c.name).html_safe
。问题出在使用html_escape
的options_for_select
辅助方法中,该方法会转义您的html_safe
将允许从options_for_select
帮助器调用html_escape
方法来避免转义空格。Try using
entities. Adding the
((" " * c.level) + c.name).html_safe
. The problem is in theoptions_for_select
helper method usinghtml_escape
, which escapes yourhtml_safe
will allow thehtml_escape
method called from theoptions_for_select
helper to avoid escaping the spaces.