Skip to content

Latest commit

 

History

History
46 lines (38 loc) · 1.03 KB

cookies.md

File metadata and controls

46 lines (38 loc) · 1.03 KB

Cookies

This recipe will help you to setup a cookie in your application.

{% hint style="warning" %} First you need an amber project generated with Amber CLI or from scratch. {% endhint %}

{% code-tabs %} {% code-tabs-item title="src/controllers/some_controller.cr" %}

class SomeController < ApplicationController
  def set_cookie
    cookies[:example] = {
      value: "a yummy cookie with amber color",
      http_only: true,
      secure: true
    }
    "Your example cookie has been cooked successfully!"
  end
end

{% endcode-tabs-item %} {% endcode-tabs %}

Then in your routes file:

{% code-tabs %} {% code-tabs-item title="config/routes.cr" %}

Amber::Server.configure do |app|
  pipeline :web do
    # pipelines...
  end

  routes :web do
    # other routes,,,
    get "/set_cookie", SomeController, :set_cookie
  end
end

{% endcode-tabs-item %} {% endcode-tabs %}

Also see more detailed information about this in Cookies Guide.