rubymiddleman

How to use cookies in a middleman ruby application?


I have a ruby middleman ruby application which contains static pages. I want to use cookies[:some_variable] in a helper class. How can I do this?

config.rb is:

configure :build do
  activate :minify_css, inline: true
  activate :minify_javascript
  activate :minify_html
  activate :relative_assets

  activate :asset_hash, ignore: ['roost_worker.js']

  activate :gzip
end

Solution

  • Middleman doesn't provide any backend code, you'll need to use javascript

    To add one inside javascript you can do

    document.cookie = "key1=value1;key2=value2;expires=date";
    

    But you can also have a look at https://github.com/sparklemotion/http-cookie

    or

    https://github.com/js-cookie/js-cookie