Living on the edgy of Sinatra English Posting

Generally, many ruby users like using edgy version of ruby things. Sinatra is also same, so many guides were based on Sinatra edgy version.

For example, some guide use "use" and "enable" methods to describe how to enable session, but they are not existed in Sinatra gem version (0.2.2). They are included in Sinatra edgy version (0.2.3).

To enable session in Gem version

set_option :session, true

is only way to enable session. However, in edgy version, you can use alternative way

enable :seesions
# or
set :sessions, true
# or
use Rack::Session::Cookie

Anyway, if you want to use Sinatra edgy version, it' so easy. First, you have to install git. Then, you can download edgy version from git-hub.

1. cd where/you/want/to/keep/sinatra/edgy/version
2. git clone git://github.com/bmizerany/sinatra.git
3. cd sinatra
4. git submodule init && git submodule update
5. cd your_project/that/will/use/sinatra/egdy/version
6. ln -s where/you/want/to/keep/sinatra/edgy/version

Finally, at the top of your Sinatra main file

$:.unshift File.dirname(__FILE__) + '/sinatra/lib'
#require 'rubygems'
require 'sinatra'

enable :sessions


Then, you can use session object.

get '/about' do
   "I'm running on Version " + Sinatra::Version.combined
end

get '/session_set' do
  session['say'] = 'hello'
end

get '/session' do
  "I'm going to say #{session['say'].to_s}"
end

You can switch version of Sinatra between gem version and edgy version anytime by comment or uncomment first and second line($:.unshift File.dirname(__FILE__) + '/sinatra/lib'; #require 'rubygems') if you have gem version Sinatra and rack. Of course, compatibility is your responsibility :-)

* References (This article is based on)
1. sinatra README.rdoc file
2. Sinatra-online book. Thanks to cschneid.

트랙백

이 글과 관련된 글 쓰기 (트랙백 보내기)
TrackbackURL : http://classpath.egloos.com/tb/4558683 [도움말]

덧글

  • 정상혁 2008/08/19 10:18 # 삭제 답글

    어학연수의 성과인가보군요 ^^
  • 허진영 2008/08/19 19:07 #

    아니 뭐 그냥 엉터리 영어예요. 그냥 작문 공부나 해볼까 해서 하고 있는데 생각보다 시간이 꽤 걸려요 ㅎㅎㅎㅎ
덧글 입력 영역


구글애드센스