Cookies

You can set cookies with the cookies helper. Example:

class PostsController < ApplicationController
  def index
    cookies[:favorite] = "chocolate"
    render json: {message: "yummy cookies set"}
  end

  def show
    cookies.merge! 'foo' => 'bar', 'bar' => 'baz'
    cookies.keep_if { |key, value| key.start_with? 'b' }
    puts "cookies.size: #{cookies.size}"
    render json: {message: "cookies behave like a hash"}
  end
end

Pro tip: Use the <- and -> arrow keys to move back and forward.

Edit this page

See a typo or an error? You can improve this page. This website is available on GitHub and contributions are encouraged and welcomed. We love pull requests from you!