ruby-on-rails - to_a - ruby string tr




Titlecase Only Capitalizes First Word in f.label (2)

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

..such as a secondary filter that doesn't reference a valid attribute, add :name... can't find documentation to support...but it works

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

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

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.





string