Method for permalink creation in ruby, based on drupal code
def create_permalink(string, separator = '-', max_size = 127)
ignore_words = ['a', 'an', 'the']
ignore_re = String.new
ignore_words.each{ |word|
ignore_re << word + '\b|\b'
}
ignore_re = '\b' + ignore_re + '\b'
permalink = string.gsub("'", separator)
permalink.gsub!(ignore_re, '')
permalink.downcase!
permalink.gsub!(/[^a-z0-9]+/, separator)
permalink = permalink.to(max_size)
return permalink.gsub(/^\\#{separator}+|\\#{separator}+$/, '')
end
It takes care of non-english characters and you can use it in any string, like: "Hello World".to_permalink #=> "hello-world".
You can add the ignored words and limit if you want, easily.