Titleize SimpleForm Labels

Posted by Weston Ganger on October 01, 2015

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:

Posted in Rails and Tagged with simple_form rails forms 

Need help on your next project or application?

I specialize in Ruby-on-Rails, AngularJS, Javascript, Bootstrap, and Hybrid Mobile Apps with Cordova & Ionic.

Contact Me

Recommended Posts