导轨 - 自定义HTML成simple_form标签 [英] Rails - Custom html into simple_form label

查看:144
本文介绍了导轨 - 自定义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 }%>

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

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