Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: Titlecase Only Capitalizes First Word in 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.

This also doesn't work:

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

Nor does this:

<%= the_label = "Time_Balance" %><br />
<%= f.label the_label.titlecase %><br />
like image 352
Drew Rush Avatar asked Sep 07 '25 17:09

Drew Rush


2 Answers

try this.

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

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.

like image 160
Doon Avatar answered Sep 09 '25 07:09

Doon


I can't comment because of my rep. To answer webaholik's question, you can use label_tag in this case:

<%= label_tag :time_balance, "Time Balance" %>
like image 41
Keller Martin Avatar answered Sep 09 '25 05:09

Keller Martin