3 Your application can store small amounts of data on the client - called cookies - that will be persisted across requests and even sessions. Rails provides easy access to cookies via the `cookies` method, which - much like the `session` - works like a hash:
6 -----------------------------------------
7 class CommentsController < ApplicationController
10 #Auto-fill the commenter's name if it has been stored in a cookie
11 @comment = Comment.new(:name => cookies[:commenter_name])
15 @comment = Comment.new(params[:comment])
17 flash[:notice] = "Thanks for your comment!"
18 if params[:remember_name]
19 # Remember the commenter's name
20 cookies[:commenter_name] = @comment.name
22 # Don't remember, and delete the name if it has been remembered before
23 cookies.delete(:commenter_name)
25 redirect_to @comment.article
27 render :action => "new"
32 -----------------------------------------
34 Note that while for session values, you set the key to `nil`, to delete a cookie value, you should use `cookies.delete(:key)`.