<br><br><div class="gmail_quote">On Sat, May 17, 2008 at 3:10 PM, Bluebie, Jenna <<a href="mailto:blueberry@creativepony.com">blueberry@creativepony.com</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
Maybe it's best to stick with simple cookie support. If people really need much more I don't feel it unfair for them to need to hack it in themselves or move up to rails and the likes.<br>
</blockquote><div><br>Move to Rails? Now that's just crazy talk. :P<br><br>Anyone who wants "complete" cookie support can add a little bit of code to their Camping app that looks like this:<br><br><div style="margin-left: 40px;">
<font size="1"><span style="font-family: courier new,monospace;">module Learning::CookieWrapper</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> def service(*a)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> @cgi_cookies = Camping::H.new</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> @default_cookie = Camping::H.new.merge({ :path => '/' })</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> response = super(*a)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> @cgi_cookies.each do |name, settings|</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> c = @default_cookie.merge(settings);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> <a href="http://c.name">c.name</a> = name</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> cookie = CGI::Cookie.new(c);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> headers['Set-Cookie'].push(cookie.to_s)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> end</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> response</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> end</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">end</span></font><br></div></div></div><br>Then, in your controllers, you can add hashes to @cgi_cookie that will be used to instantiate CGI::Cookie objects. <br>
<br><b>Example Code:</b><br><br><a href="http://github.com/beppu/learning/commit/c6559d42adaf8624d836ecb8b4f6bfaf53255e47">http://github.com/beppu/learning/commit/c6559d42adaf8624d836ecb8b4f6bfaf53255e47</a><br><br><a href="http://github.com/beppu/learning/tree/master/learning.rb">http://github.com/beppu/learning/tree/master/learning.rb</a> (lines 35-48, 51)<br>
<br><a href="http://github.com/beppu/learning/tree/master/learning/controllers.rb">http://github.com/beppu/learning/tree/master/learning/controllers.rb</a> (lines 142-150)<br><br><b>Live Demo:</b><br><br><a href="http://learning.kicks-ass.org/">http://learning.kicks-ass.org/</a><br>
<br><div style="margin-left: 40px;"><font face="georgia,serif">Submit a few bits of wisdom, and then go to:<br><br></font><div style="margin-left: 40px;"><a href="http://learning.kicks-ass.org/env">http://learning.kicks-ass.org/env</a><br>
<br><div style="margin-left: 40px;"><font face="georgia,serif">Look at HTTP_COOKIE to verify that Camping can indeed have "complete" cookie support w/ just a little bit of extra code.<br><br>Alternatively, if you have the Web Developer Toolbar for Firefox, you can look at [Cookies | View Cookie Information].<br>
<br></font></div></div></div><font face="arial,sans-serif">--beppu<br><br></font>