Rails - 自定义 html 到 simple_form 标签 [英] Rails - Custom html into simple_form label

查看:32
本文介绍了Rails - 自定义 html 到 simple_form 标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试自定义 simple_form 关联的输出,基本上我需要在两行上显示一个复选框标签.我的想法是在标签"中添加一个br"标签,但不幸的是它被转义了所以它实际上显示了br"而不是换行

I'm trying to customize the output of a simple_form association, basically I need to display a checkbox label on two lines. My idea was adding a "br" tag into the "label", but unfortunately it gets escaped so it display actually "br" instead of going to a new line

我使用 lambda 来自定义标签输出

I use a lambda for customizing the label output

<%= f.association :item, :as => :check_boxes, :collection => current_user.items, :label => false, :label_method => lambda { |item| "#{item.city.capitalize},<br> #{item.address}" }%>

这会在标签字符串中生成一个转义的 br,我怎么能在两行上显示标签?

this produces an escaped br into the label string, how could I display the label on two lines?

推荐答案

在你不想被转义的字符串上调用 html_safe 方法.

call html_safe method on the string you want not to be escaped.

<%= f.association :item, :as => :check_boxes, :collection => current_user.items, :label => false, :label_method => lambda { |item| "#{item.city.capitalize},<br> #{item.address}".html_safe }%>

这篇关于Rails - 自定义 html 到 simple_form 标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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