Ruby on rails f.label为复选框 [英] Ruby on rails f.label for a check box

查看:292
本文介绍了Ruby on rails f.label为复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这个视图中有一个代码块:

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

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

'i' a_b_c 。但它在视图上显示为 a b c ,不带下划线。请让我知道如何打印字符串,因为它是在页面上,没有修剪下划线。还请让我知道为什么f.label正在修剪下划线。
感谢

解决方案

标签有助于80%在传递它的情况下,一个属性符号,它通常包含下划线。在生成标签文本时,它会删除下划线,因为大多数时候您不希望标签读取 First_Name



您可以传递一个字符串作为第二个参数,以覆盖标签文本的显示方式。

  <%= f.label(i,a_b_c)%>所以,也许你可以试试这样的东西?

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


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. But it is displayed as a b c without underscores on the view. 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. Thanks

解决方案

label is helpful for 80% of the cases where you pass it a property symbol, which will often contain underscores. 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.

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) %>

这篇关于Ruby on rails f.label为复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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