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 

Want me to help develop your next project or application?

Contact Us

Specializing in Ruby-on-Rails, Javascript, Multi-Platform Electron Desktop Apps and Hybrid Cordova Mobile Apps.

Recommended Posts