I have a real simple question here. I only want to know if there is an existing Rails way to accomplish this, because I don’t want to re-write something that is already in the framework.
Think of an underscored variable name like “this_is_an_example”. Is there a quick way to turn that into “This is an example” or even “This Is An Example” using Rails? I know ActiveRecord prints table column names like “first_name” as “First Name”, how is it doing that?
Thanks!
The thing that already exists is called the Inflector. Check out the documentation at http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html.
All the methods listed there are new methods on Strings, so in your case: