1
votes

In my Rails 3.2 project, I have a form to create a new post in new.html.erb in app/views/posts/

<%= form_for(@post) do |post_form| %>
  ...
  <div class="field">
    <%= post_form.label :title %><br />
    <%= post_form.text_field :title %>
  </div>
 ...
  <div class="actions">
    <%= post_form.submit %>
  </div>
<% end %>

I want to display the title label as TITLE, so I changed the code to post_form.label :TITLE %>, but it still displays Title. How can I display it as TITLE?

2
You can directly use Label tag as well or Just pass "TITLE" in string instead of passing :title in the <%= post_form.label :title %> - Arihant Godha
In general HTM tag <label class="xyz" for="title">TITLE</label> - Arihant Godha

2 Answers

3
votes

Since this is a matter of presentation on screen as opposed to content, rather than do the transformation in eruby code, this really ought to be done in CSS:

.field label {
  text-transform: uppercase;
}

If you only want to modify the :title input's label rather than all labels having the same class, add a different class or use the input's id in the CSS rule.

If you insist on up-casing it in Rails, use the second parameter to .label:

<%= post_form.label :title, :title.to_s.upcase %>
2
votes

You can modify the form label as follows:

<%= post_form.label(:title, "TITLE") %>

Source: http://guides.rubyonrails.org/form_helpers.html