Does rails have an opposite of `parameterize` for strings?
No, there is not. parameterize
is a lossy conversion, you can't convert it back.
Here's an example. When you convert
My Awesome Pizza
into
my-awesome-pizza
you have no idea if the original string was
My Awesome Pizza
MY AWESOME PIZZA
etc. This is a simple example. However, as you can see from the source code, certain characters are stripped or converted into a separator (e.g. commas) and you will not be able to recover them.
If you just want an approximate conversion, then simply convert the dashes into spaces, trim multiple spaces and apply an appropriate case conversion.
In Rails there is titleize
(source):
"this-is-my-parameterized-string".titleize
=> "This Is My Parameterized String"
"hello-world foo bar".titleize
=> "Hello World Foo Bar"
As mentioned above, this isn't going to revert the string to its pre-parameterized form, but if that's not a concern, this might help!