Rails:Titlecase 仅将 f.label 中的第一个单词大写 [英] Rails: Titlecase Only Capitalizes First Word in f.label

查看:40
本文介绍了Rails:Titlecase 仅将 f.label 中的第一个单词大写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第一行代码做我想要的,第二行只大写第一个单词:

The first line of code does what I want, the second only capitalizes the first word:

<%= the_label = "Time_Balance".titlecase %><br />
<%= f.label "Time_Balance".titlecase %><br />

我想对输入标签进行标题化,但我无法管理它.

I want to titlecase the input label, but I just can't manage it.

这也不起作用:

<%= the_label = "Time_Balance".titlecase %><br />
<%= f.label the_label %><br />

这也不行:

<%= the_label = "Time_Balance" %><br />
<%= f.label the_label.titlecase %><br />

推荐答案

试试这个.

<%= f.label :time_balance, "Time Balance" %> <br />

Label 期望第一个参数是表单所针对的对象上的 method_name,并且默认只使用它,除非您明确指定它作为第二个参数(内容/选项)的一部分.

Label expects the first argument to be the method_name on the object the form is for, and defaults to just using it, unless you specify it explicitly as part of the second argument which is content/options.

这篇关于Rails:Titlecase 仅将 f.label 中的第一个单词大写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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