Topic: Regular Expressions for Clean URLS
I am using permalinks for quite a few of my applications and am not quite getting my REGEXPs right
My aim is to replace spaces with a hyphen "-" character and to ignore any characters that are not alphanumeric.
@attributes['permalink'] = title.downcase.gsub(/\s+/, '-').gsub(/[^a-zA-Z0-9_]+/, '')
This seems to get the alpha-numeric part right, but there are no dashes and my words get sandwiched together.
Another issue I have is that this method is sitting in my model.rb file and I will need it to be used in many places. I know that application.rb is the place for all your controllers to inherit their behavior, but where do I go for models?