Ruby Sinatra https ssl redirect helper

Wrote this little thing when I had a problem. Basically, what was happening was that I couldn’t get the sinatra to redirect to SSL when behind my authentication. This code fixes that by making a new helper to do it for you:

helpers do

  def redirect_ssl(path,code=301)

    redirect #{"https://#{}” unless == ‘localhost’}#{path}“, code



Use it with this snippet:

redirect_ssl /secure-redirect, 301 # optional code

That’s it!