Simple Tutsplus demo app utilizing Sinatra and Redis
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
|
|
require 'sinatra' require 'redis' require 'haml' require 'sass'
redis = Redis.new
helpers do include Rack::Utils alias_method :h, :escape_html
def random_string(length) rand(36**length).to_s(36) end end
get ('/styles/main.css'){ scss :styles }
get '/' do haml :index end
post '/' do if params[:url] and not params[:url].empty? @shortcode = random_string 5
redis.setnx "links:#{@shortcode}", params[:url] end haml :index end
get '/:shortcode' do @url = redis.get "links:#{params[:shortcode]}" redirect @url || '/' end
|