Sinatra Title Slugs
- by Ethan Turkeltaub
I'm trying to create a slug helper in Sinatra. Here's the code (as seen here):
helpers do
def sluggify(title)
accents = {
['á','à','â','ä','ã'] => 'a',
['Ã','Ä','Â','À'] => 'A',
['é','è','ê','ë'] => 'e',
['Ë','É','È','Ê'] => 'E',
['í','ì','î','ï'] => 'i',
['Î','Ì'] => 'I',
['ó','ò','ô','ö','õ'] => 'o',
['Õ','Ö','Ô','Ò','Ó'] => 'O',
['ú','ù','û','ü'] => 'u',
['Ú','Û','Ù','Ü'] => 'U',
['ç'] => 'c', ['Ç'] => 'C',
['ñ'] => 'n', ['Ñ'] => 'N'
}
accents.each do |ac,rep|
ac.each do |s|
title = title.gsub(s, rep)
end
end
title = title.gsub(/[^a-zA-Z0-9 ]/,"")
title = title.gsub(/[ ]+/," ")
title = title.gsub(/ /,"-")
title = title.downcase
end
end
I keep getting this error:
private method `gsub' called for nil:NilClass
What exactly is going wrong?