Module: Sinatra::Cookies
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Defined in: | sinatra-contrib/lib/sinatra/cookies.rb |
Overview
Easy way to deal with cookies
Usage
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
Classic Application
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...
Modular Application
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