작동하지 않음이 같은시나 응용 프로그램이 작동해야합니다간단한시나 세션 <a href="http://www.sinatrarb.com/faq.html#sessions" rel="nofollow">the Sinatra FAQ</a>에 따르면
enable :sessions
class MyApp < Sinatra::Base
get '/foo' do
session[:message] = 'Hello World!'
redirect to('/bar')
end
get '/bar' do
$stderr.puts session[:message]
session[:message] # => 'Hello World!'
end
end
은 주어진 config.ru
같은 :
require 'sinatra'
require './test.rb' # which contains the above MyApp
run MyApp
과를 통해 그것을 호출 :
thin -R config.ru -p 4567 start
Sinatra 코드가 실행되는 동안 쿠키를 설정하지 않습니다. 당신은 curl -vL http://localhost:4567/foo
출력에서 볼 수 있습니다
* Hostname was NOT found in DNS cache
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 4567 (#0)
> GET /foo HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost:4567
> Accept: */*
>
< HTTP/1.1 302 Moved Temporarily
< Content-Type: text/html;charset=utf-8
< Location: http://localhost:4567/bar
< Content-Length: 0
< X-XSS-Protection: 1; mode=block
< X-Content-Type-Options: nosniff
< X-Frame-Options: SAMEORIGIN
< Connection: keep-alive
* Server thin is not blacklisted
< Server: thin
<
* Connection #0 to host localhost left intact
* Issue another request to this URL: 'http://localhost:4567/bar'
* Found bundle for host localhost: 0x1180760
* Re-using existing connection! (#0) with host localhost
* Connected to localhost (127.0.0.1) port 4567 (#0)
> GET /bar HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost:4567
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: text/html;charset=utf-8
< Content-Length: 0
< X-XSS-Protection: 1; mode=block
< X-Content-Type-Options: nosniff
< X-Frame-Options: SAMEORIGIN
< Connection: keep-alive
* Server thin is not blacklisted
< Server: thin
<
* Connection #0 to host localhost left intact
플러스의 $stderr.puts session[:message]
메시지를 방출 아니라 단지 빈 줄 수 없습니다.
use Rack::Session::Cookie, :key => 'rack.session',
:domain => 'foo.com',
:path => '/',
:expire_after => 2592000, # In seconds
:secret => 'change_me'
이 thin
1.6.3, rack
1.6.0 및 sinatra
1.4.5 함께 : 다음과 Swtiching
enable :sessions
도 영향을주지 않습니다.
어디로 잘못 가고 있습니까? 잠에서 잠깐 비참하게 짧다. ...
고마워! 지금 당신이를 사용할 때 실행되는 응용 프로그램 인 Sinatra::Application
앱에 대한 세션을 활성화입니다 라인으로
class MyApp < Sinatra::Base
enable :sessions
#...
:
실제로 쿠키 헤더가 흐르는 것을 보는 것은 방대한 개선입니다. 많은 감사합니다! – CommonsWare