Cookie Crumbs

A Rails plugin that adds the ability to create sub-cookies within a controller when you need to store more than domain limit of 20 cookies.

Overview

Cookie Crumbs is a Rails plugin that adds the ability to store more than one value for a single cookie. This is helpful in applications that need to store more than the maximum 20 allowed cookies.

Download

Subversion Repository:

$ http://svn.maintainable.com/public/rails/plugins/cookie_crumbs

To install for use in your Rails project:

$ ./script/plugin install \
http://svn.maintainable.com/public/rails/plugins/cookie_crumbs

How it Works

In the Rails Controller

The plugin will add a new crumbs method to your controller classes to access the data.

def index
  # setting crumbs - these all save to the same 'widget' cookie
  crumbs[:widget] = { :favorites => "open", :sources => "closed" }
  # or
  crumbs[:widget][:favorites] = "open"
  crumbs[:widget][:sources]   = "closed"

  # getting crumbs
  crumbs[:widget] # => { :favorites => "open", :sources => "closed" }
  crumbs[:widget][:favorites] # => "open"

  # deleting crumbs
  crumbs[:widget].delete :favorites
end

In the Javascript

The Javascript library extends the document object with various methods for manipulating both cookies and crumbs.

// cookies (set/get/delete)
document.setCookie('sidebar', 'open');
document.getCookie('sidebar');
document.delCookie('sidebar');

// setting crumbs - these all save to the same 'widget' cookie
document.setCrumb('widget', 'favorites' 'open');
document.setCrumb('widget', 'sources'   'closed');

// getting crumbs
document.getCrumb('widget', 'favorites'); // => "open"

// deleting crumbs
document.delCrumb('widget', 'sources');