Ruby on rails f.label for a check box

空扰寡人 提交于 2019-12-11 13:04:44

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/11232115/ruby-on-rails-f-label-for-a-check-box

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!