如何将HTML标记放入<;标签>;在RubyonRails中?
如何将如何将HTML标记放入<;标签>;在RubyonRails中?,html,ruby-on-rails,Html,Ruby On Rails,如何将标签放入f.label标签中 <%= f.label :test %> 请求的输出: <label for="test">test<span>*</span></label> 测试* 这应该可以做到: <%= f.label :test, 'test<span>*</span>'.html_safe %> 您需要告诉rails,您给它的字符串不需要消毒。使用String#html_-s
标签放入f.label
标签中
<%= f.label :test %>
请求的输出:
<label for="test">test<span>*</span></label>
测试*
这应该可以做到:
<%= f.label :test, 'test<span>*</span>'.html_safe %>
您需要告诉rails,您给它的字符串不需要消毒。使用
String#html_-safe
<%= f.label :test, "test<span>*</span>".html_safe %>
标签接受块,因此您可以执行以下操作:
<%= f.label :test do %>
<span>*</span>
<%end%>
*
您将通过以下方式获得转义输出:testspan*/span
这是最好的方式