Skip to content

Instantly share code, notes, and snippets.

@brunitob
Created April 25, 2017 23:46
Show Gist options
  • Save brunitob/dc760c9b966b0f1dce374f1de66018af to your computer and use it in GitHub Desktop.
Save brunitob/dc760c9b966b0f1dce374f1de66018af to your computer and use it in GitHub Desktop.
How to generate urls for tonic images
#barlinks
@bar = Bar.all
@bar.each do |bar|
puts bar.slug
end
#http://tonicapp.s3.amazonaws.com/back-in-black-recoleta.jpg
def to_slug
#strip the string
ret = self.strip
#blow away apostrophes
ret.gsub! /['`]/,""
# @ --> at, and & --> and
ret.gsub! /\s*@\s*/, " at "
ret.gsub! /\s*&\s*/, " and "
#replace all non alphanumeric, underscore or periods with underscore
ret.gsub! /\s*[^A-Za-z0-9\.\-]\s*/, '_'
#convert double underscores to single
ret.gsub! /_+/,"_"
#strip off leading/trailing underscore
ret.gsub! /\A[_\.]+|[_\.]+\z/,""
ret
end
#bar-drink links
@bar.each do |bar|
bar.drinks.each do |drink|
puts "#{bar.slug}-#{drink.name.to_slug.downcase}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment