Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does f.label transform 'ALL' caps string to 'All' caps

I have an object that whose values are all caps, and I would like the f.label helper to print it out as all caps - without having to do a CSS transform.

Right now, if I have the string AAPL in my object, f.label spits it out as Aapl.

The reason I don't want to use a CSS transform is because the value of the object will not ALWAYS need to be all uppercase. I just want the f.label to output it exactly as it is stored in the db - preferably without any CSS shenanigans.

How do I do that?

like image 923
marcamillion Avatar asked Oct 04 '12 09:10

marcamillion


2 Answers

It sounds like something is calling humanize(). This seems to happen, when Rails translates an element name to a label title. Probably you should define the text for the label explicit to it's form element.

<%= f.label(:aapl, 'AAPL') %>

or even

<%= f.label(:aapl, @yourVar) %>

Another option for you might be the translation ability, which Rails provides. This is valid for Rails > 3.1!

In your view:

<% form_for @post do |f| %>
  <%= f.label :title %>
  <%= f.text_field :title %>
  <%= f.submit %>
<% end %>

In your en.yml:

en:
  helpers:
    label:
      post:
        title: 'Your Title'
like image 196
Robin Avatar answered Nov 13 '22 16:11

Robin


Try this:

f.label(topic).upcase.html_safe
like image 40
sampi Avatar answered Nov 13 '22 15:11

sampi