Skip to content

Instantly share code, notes, and snippets.

@yuyalush
Created June 20, 2011 10:33
Show Gist options
  • Save yuyalush/1035415 to your computer and use it in GitHub Desktop.
Save yuyalush/1035415 to your computer and use it in GitHub Desktop.
Sinatra+Haml+Omniauth sample
動作環境
Ruby1.9.2
1. setup
gemで以下のものをインストール
sinatra
omniauth
haml
shotgun
2. ファイルを配置
app.rbとconfig.ruを配置
viewsというディレクトリを作り、そこへindex.hamlとindex2.hamlを配置する
3. サーバを起動する
# shotgun -o 0.0.0.0 -p 3000
http://localhost:3000/
にアクセスする
# -*- encoding: UTF-8 -*-
require 'rubygems'
require 'sinatra'
require 'haml'
require 'omniauth'
set :haml, {:format => :html5}
enable :sessions, :logging
use OmniAuth::Builder do
provider :twitter, 'CONSUMER_KEY', 'CONSUMER_SECRET'
end
get '/' do
haml :index
end
get '/auth/:name/callback' do
@auth = request.env['omniauth.auth']
haml :index2
end
require './app.rb'
run Sinatra::Application
!!!
%html
%head
%meta{:charset => "utf-8"}
%title Sinatra + Haml + Omniauthテスト
%body
%a{:href => '/auth/twitter'} Sign in Twitter
!!!
%html
%head
%meta{:charset => "utf-8"}
%title Sinatra + Haml + Omniauthテスト
%body
%p Finish!
%pre= @auth
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment