Rails: Titlecase Only Capitalizes First Word in f.label

后端 未结 3 704
名媛妹妹
名媛妹妹 2021-02-04 00:40

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

<%= the_label = \"Time_Balance\".titlecase %>
<%= f.lab
相关标签:
3条回答
  • 2021-02-04 00:55

    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.

    0 讨论(0)
  • 2021-02-04 00:57

    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" %>
    
    0 讨论(0)
  • 2021-02-04 01:06

    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 />
    
    0 讨论(0)
提交回复
热议问题