ruby-on-railsforms

Maintaining Capitilzation in Rails 7 form.label


I have created a form using Rails 7 form helpers. The part giving me trouble is the form.label:

<%= form.label "Color: RGB" %>

Instead of outputting the text as shown, I get label text as: Color: rgb

What must I do to get the label with the capitalization that I used for the form.label?


Solution

  • You can pass additional options to the label helper. If you pass 2 parameters, it will use the first one to define the for attribute of your <label> tag and the second one will be the text content displayed to the user.

    If you define it like this:

    <%= form.label "color_rgb", "Color: RGB" %>
    

    It will render the following:

    <label for="color_rgb">Color: RGB</label>