Browse files

Added example usage of cookies to hello app.

  • Loading branch information...
1 parent 5bb8cf9 commit ce09c604f6948d18662f9a1f0c8d600e178146c5 @thatismatt committed Jul 6, 2010
Showing with 19 additions and 0 deletions.
  1. +12 −0 examples/hello/controllers/home.js
  2. +6 −0 examples/hello/views/home/cookie.html
  3. +1 −0 examples/hello/views/master.html
View
12 examples/hello/controllers/home.js
@@ -19,3 +19,15 @@ this.another = function() {
this.redir = function() {
return redirect('/product/details/1');
};
+
+this.cookie = function() {
+ var aCookie = this.cookie.get('a') === 'red' ? 'blue' : 'red';
+ var bCookie = (parseInt(this.cookie.get('b'), 10) || 0) + 1;
+ this.cookie.set('a', aCookie);
+ this.cookie.set('b', bCookie);
+ return view({
+ title: 'Cookies',
+ a: aCookie,
+ b: bCookie
+ });
+};
View
6 examples/hello/views/home/cookie.html
@@ -0,0 +1,6 @@
+<p>
+ The cookie a's value is: <%= a %>
+</p>
+<p>
+ The cookie b's value is: <%= b %>
+</p>
View
1 examples/hello/views/master.html
@@ -11,6 +11,7 @@
<li><a href="/home/another">An action sharing a view</a></li>
<li><a href="/product">List of products</a></li>
<li><a href="/error">Throw an error</a></li>
+ <li><a href="/home/cookie">Cookie example</a></li>
</ul>
<div class="main">
<%= main %>

0 comments on commit ce09c60

Please sign in to comment.