Do rails have the opposite of `parameterization` for strings?

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

+7
source share
3 answers

No no. parameterize is a lossy transformation, you cannot return it.

Here is an example. When you convert

 My Awesome Pizza 

in

 my-awesome-pizza 

you don't know 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 , some characters are deleted or converted to a separator (for example, commas), and you cannot recover them.

If you just want an approximate transformation, just convert the strokes to spaces, trim a few spaces and apply the appropriate case transformation.

+14
source

I'm with Simone on this, but you can always go with

 def deparametrize(str) str.split("-").join(" ").humanize end 

:)

+8
source

Rails has a 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 will not return the string to the pre-parameterized form, but if this is not a problem, it can help!

0
source

All Articles