简体   繁体   English

Ruby on Rails f.label为复选框

[英]Ruby on rails f.label for a check box

I have a block of code in my view like this: 我认为这样的代码块如下:

<% @map[value].each do |i| %> 

            <p><%= f.check_box(i)%> <%= f.label(i)%><br /><p>
            <% end %>

The value 'i' is having string like a_b_c . 'i'具有类似于a_b_c字符串。 But it is displayed as abc without underscores on the view. 但是在视图上显示为abc没有下划线。 Please let me know how to print the string as it is on the page without trimming the underscores. 请让我知道如何在不修剪下划线的情况下按页面上的原样打印字符串。 Also please let me know why f.label is trimming the underscores. 另外请让我知道为什么f.label会修剪下划线。 Thanks 谢谢

label is helpful for 80% of the cases where you pass it a property symbol, which will often contain underscores. label可在80%的情况下为您传递属性符号(通常包含下划线)的情况下很有帮助。 It strips out the underscores when generating the label text because most of the time you don't want the label to read something like First_Name . 生成标签文本时,它会删除下划线,因为大多数时候您不希望标签读取First_Name

You can pass a string as a second argument to override what the text of the label appears as. 您可以将字符串作为第二个参数传递,以覆盖标签文本的外观。

<%= f.label(i, "a_b_c") %>

So maybe you can try something like this? 所以也许您可以尝试这样的事情?

<%= f.label(i, i) %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM