Cookies subsequently sent by the browser can be read from the request
.
module Bookshelf
module Actions
module Books
class Index < Bookshelf::Action
def handle(request, response)
request.cookies["tasty_cookie"] # => "strawberry"
end
end
end
end
end
:path
- (nil
by default), a relative URL:max_age
-Integer
(nil
by default), cookie duration expressed in seconds:secure
-Boolean
(true
by default if using SSL), restrict cookies to secure connections:httponly
-Boolean
(true
by default), restrict JavaScript access to cookies
This configuration can be overridden within an action passing a hash, which has a value
key representing the value of the cookie, and any properties to override.
module Bookshelf
module Actions
module Books
class Index < Bookshelf::Action
def handle(request, response)
response.cookies["longer_lived_cookie"] = {
value: "anzac_biscuit",
}
end
end
end
end
end
To prevent cookies from being set in your actions, provide the following config to your app:
# config/app.rb
module Bookshelf
class App < Hanami::App
config.actions.cookies = nil
end