<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Module: ActionController::Cookies</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta http-equiv="Content-Script-Type" content="text/javascript" /> <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" /> <script type="text/javascript"> // <![CDATA[ function popupCode( url ) { window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400") } function toggleCode( id ) { if ( document.getElementById ) elem = document.getElementById( id ); else if ( document.all ) elem = eval( "document.all." + id ); else return false; elemStyle = elem.style; if ( elemStyle.display != "block" ) { elemStyle.display = "block" } else { elemStyle.display = "none" } return true; } // Make codeblocks hidden by default document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" ) // ]]> </script> </head> <body> <div id="classHeader"> <table class="header-table"> <tr class="top-aligned-row"> <td><strong>Module</strong></td> <td class="class-name-in-header">ActionController::Cookies</td> </tr> <tr class="top-aligned-row"> <td><strong>In:</strong></td> <td> <a href="../../files/lib/action_controller/cookies_rb.html"> lib/action_controller/cookies.rb </a> <br /> </td> </tr> </table> </div> <!-- banner header --> <div id="bodyContent"> <div id="contextContent"> <div id="description"> <p> <a href="Cookies.html">Cookies</a> are read and written through ActionController#cookies. </p> <p> The <a href="Cookies.html#M000176">cookies</a> being read are the ones received along with the request, the <a href="Cookies.html#M000176">cookies</a> being written will be sent out with the response. Reading a cookie does not get the cookie object itself back, just the value it holds. </p> <p> Examples for writing: </p> <pre> # Sets a simple session cookie. cookies[:user_name] = "david" # Sets a cookie that expires in 1 hour. cookies[:login] = { :value => "XJ-122", :expires => 1.hour.from_now } </pre> <p> Examples for reading: </p> <pre> cookies[:user_name] # => "david" cookies.size # => 2 </pre> <p> Example for deleting: </p> <pre> cookies.delete :user_name </pre> <p> Please note that if you specify a :domain when setting a cookie, you must also specify the domain when deleting the cookie: </p> <pre> cookies[:key] = { :value => 'a yummy cookie', :expires => 1.year.from_now, :domain => 'domain.com' } cookies.delete(:key, :domain => 'domain.com') </pre> <p> The option symbols for setting <a href="Cookies.html#M000176">cookies</a> are: </p> <ul> <li><tt>:value</tt> - The cookie‘s value or list of values (as an array). </li> <li><tt>:path</tt> - The path for which this cookie applies. Defaults to the root of the application. </li> <li><tt>:domain</tt> - The domain for which this cookie applies. </li> <li><tt>:expires</tt> - The time at which this cookie expires, as a Time object. </li> <li><tt>:secure</tt> - Whether this cookie is a only transmitted to HTTPS servers. Default is <tt>false</tt>. </li> <li><tt>:httponly</tt> - Whether this cookie is accessible via scripting or only HTTP. Defaults to <tt>false</tt>. </li> </ul> </div> </div> <div id="method-list"> <h3 class="section-bar">Methods</h3> <div class="name-list"> <a href="#M000176">cookies</a> <a href="#M000175">included</a> </div> </div> </div> <!-- if includes --> <div id="section"> <!-- if method_list --> <div id="methods"> <h3 class="section-bar">Public Class methods</h3> <div id="method-M000175" class="method-detail"> <a name="M000175"></a> <div class="method-heading"> <a href="Cookies.src/M000175.html" target="Code" class="method-signature" onclick="popupCode('Cookies.src/M000175.html');return false;"> <span class="method-name">included</span><span class="method-args">(base)</span> </a> </div> <div class="method-description"> </div> </div> <h3 class="section-bar">Protected Instance methods</h3> <div id="method-M000176" class="method-detail"> <a name="M000176"></a> <div class="method-heading"> <a href="Cookies.src/M000176.html" target="Code" class="method-signature" onclick="popupCode('Cookies.src/M000176.html');return false;"> <span class="method-name">cookies</span><span class="method-args">()</span> </a> </div> <div class="method-description"> <p> Returns the cookie container, which operates as described above. </p> </div> </div> </div> </div> <div id="validator-badges"> <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p> </div> </body> </html>