Titleize SimpleForm Labels

Posted by Weston Ganger

I got annoyed not having all the words capitalized using simple_form. Heres how to titleize them automatically.

Change the line: config.label_text in config/initializers/simple_form.rb


### config/initializers/simple_form.rb
config.label_text = lambda { |label, required| "#{required} #{label.gsub(/\b\w/, &:upcase)}: " }

You can replace the gsub with whatever string manipulation you want but I find this one work well for the most part except for something like the example below.


### config/initializers/simple_form.rb
<%= f.input :text, label: "iOS" %>

# label output will be: IOS


Related External Links:

Article Topic:Software Development - Rails

Date:October 01, 2015

Recommended Posts