Module: Sinatra::Cookies
- Defined in:
- lib/sinatra/cookies.rb
Overview
Sinatra::Cookies
Easy way to deal with cookies
Usage
Allows you to read cookies:
get '/' do
"value: #{[:something]}"
end
And of course to write cookies:
get '/set' do
[:something] = 'foobar'
redirect to('/')
end
And generally behaves like a hash:
get '/demo' do
.merge! 'foo' => 'bar', 'bar' => 'baz'
.keep_if { |key, value| key.start_with? 'b' }
foo, = .values_at 'foo', 'bar'
"size: #{.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 you will 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
Defined Under Namespace
Classes: Jar