blake.app

Rails parameterize

I learned about a new Rails helper method today for formatting strings used for urls called parameterize. It will remove special characters like spaces and periods from strings and by default separate them with dashes. It also lowercases the string. Remember this is part of Rails not Ruby, so as a quick example let’s open up the Rails Console:

slug = "Blake Erickson".parameterize

and it will return:

"blake-erickson"

I’m glad I found about parameterize because I feel like it is something I would re-invent if I didn’t know it existed.