RailsGrunt

a noob working the ruby railroad.

cool snippet of code to replace empty spaces in rails.

May 23rd, 2007

@yourStringOfData.gsub(/\s+/, ’-’)

so simple. what did i use this for?

well i am using acts as sluggable in one of my applications and wanted to give the user a link to a post/note that they wrote so they can send it to their friends/family/etc…well basically since acts as sluggable uses your url + if + title, all i needed to do was get the title of whatever, and replace all spaces in the title with the line dash. hopefully this tidbit helps someone.

hmm, maybe i should create a top 10 tricks all new ror programmers should know.

Sorry, comments are closed for this article.