Drew Rush
Drew Rush

Reputation: 720

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 />

Upvotes: 27

Views: 9727

Answers (3)

Keller Martin
Keller Martin

Reputation: 150

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

Upvotes: 2

webaholik
webaholik

Reputation: 1795

F! What if I can't use "f." ?

..such as a secondary filter that doesn't reference a valid attribute

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

Upvotes: 0

Doon
Doon

Reputation: 20232

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.

Upvotes: 70

Related Questions