Easy way to deal with cookies
Allows you to read cookies:
get '/' do
"value: #{cookies[:something]}"
end
And of course to write cookies:
get '/set' do
cookies[:something] = 'foobar'
redirect to('/')
end
And generally behaves like a hash:
get '/demo' do
cookies.merge! 'foo' => 'bar', 'bar' => 'baz'
cookies.keep_if { |key, value| key.start_with? 'b' }
foo, bar = cookies.values_at 'foo', 'bar'
"size: #{cookies.length}"
end
In a classic application simply require the helpers, and start using them:
require "sinatra" require "sinatra/cookies" # The rest of your classic application code goes here...
In a modular application you need to require the helpers, and then tell the application to use them:
require "sinatra/base" require "sinatra/cookies" class MyApp < Sinatra::Base helpers Sinatra::Cookies # The rest of your modular application code goes here... end
Generated with the Darkfish Rdoc Generator 2.