Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does rails have an opposite of `parameterize` for strings?

I used parameterize method. I want to de-parameterize it. Is there a method to do the opposite of parameterize?

like image 382
sank Avatar asked Jun 16 '15 09:06

sank


1 Answers

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.

like image 195
Simone Carletti Avatar answered Sep 23 '22 04:09

Simone Carletti