Cookies
This recipe will help you to setup a cookie in your application.
First you need an amber project generated with Amber CLI or from scratch.
src/controllers/some_controller.cr
1
class SomeController < ApplicationController
2
def set_cookie
3
cookies[:example] = {
4
value: "a yummy cookie with amber color",
5
http_only: true,
6
secure: true
7
}
8
"Your example cookie has been cooked successfully!"
9
end
10
end
Copied!
Then in your routes file:
config/routes.cr
1
Amber::Server.configure do |app|
2
pipeline :web do
3
# pipelines...
4
end
5
6
routes :web do
7
# other routes,,,
8
get "/set_cookie", SomeController, :set_cookie
9
end
10
end
Copied!
Also see more detailed information about this in Cookies Guide.
Last modified 3yr ago
Copy link