<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Geoff Evason &#187; cookies</title>
	<atom:link href="http://geoff.evason.name/tag/cookies/feed/" rel="self" type="application/rss+xml" />
	<link>http://geoff.evason.name</link>
	<description></description>
	<lastBuildDate>Wed, 30 Nov 2011 03:41:06 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Set Cookie in HTML Body for Rails 2.3.2</title>
		<link>http://geoff.evason.name/2009/05/26/set-cookie-in-html-body-for-rails-232/</link>
		<comments>http://geoff.evason.name/2009/05/26/set-cookie-in-html-body-for-rails-232/#comments</comments>
		<pubDate>Tue, 26 May 2009 04:33:55 +0000</pubDate>
		<dc:creator>Geoff</dc:creator>
				<category><![CDATA[tech]]></category>
		<category><![CDATA[cookies]]></category>
		<category><![CDATA[passenger]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://geoff.evason.name/?p=69</guid>
		<description><![CDATA[I recently upgraded an app to rails 2.3 and on many pages on my local machine the top of the HTML body included something like this:

Set-Cookie: _myapp_session_id=BAh7B...; path=/; HttpOnly

I couldn&#8217;t figure out what was happening until I found this forum post which explained that the problem was related to passenger 2.0.6.  To fix the [...]]]></description>
			<content:encoded><![CDATA[<p>I recently upgraded an app to rails 2.3 and on many pages on my local machine the top of the HTML body included something like this:</p>
<pre><code>
Set-Cookie: _myapp_session_id=BAh7B...; path=/; HttpOnly
</code></pre>
<p>I couldn&#8217;t figure out what was happening until I found <a href="http://railsforum.com/viewtopic.php?id=27180" title"rails 2.3 cookie in body">this forum post</a> which explained that the problem was related to passenger 2.0.6.  To fix the problem I just needed to update the version of passenger I was running.</p>
<p>To update passenger (on a mac) was pretty simple.  Just run the following 2 commands:</p>
<pre><code>
sudo gem install passenger
sudo passenger-install-apache2-module
</code></pre>
<p>Depending on how you set up your local apache instance, you may also need to update the config. I needed to update /etc/apache2/httpd.conf to</p>
<pre><code>
LoadModule passenger_module /Library/Ruby/Gems/1.8/gems/passenger-2.1.2/ext/apache2/mod_passenger.so
PassengerRoot /Library/Ruby/Gems/1.8/gems/passenger-2.1.2
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://geoff.evason.name/2009/05/26/set-cookie-in-html-body-for-rails-232/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Railscasts Does It Again : Site Wide Announcements</title>
		<link>http://geoff.evason.name/2008/05/27/railscasts-does-it-again-site-wide-announcements/</link>
		<comments>http://geoff.evason.name/2008/05/27/railscasts-does-it-again-site-wide-announcements/#comments</comments>
		<pubDate>Tue, 27 May 2008 22:11:46 +0000</pubDate>
		<dc:creator>Geoff</dc:creator>
				<category><![CDATA[tech]]></category>
		<category><![CDATA[cookies]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://geoff.evason.name/?p=46</guid>
		<description><![CDATA[A note to all rails developers, new and old.  If you&#8217;re not following Ryan Bates&#8217; Railcasts, you should be.
I follow a variey of rails blogs and lean on a number of resources quite regularly, but the Railscasts are consistently the most useful.  There are now over 100 railscast, each one a roughly 5 minute screencast [...]]]></description>
			<content:encoded><![CDATA[<p>A note to all rails developers, new and old.  If you&#8217;re not following Ryan Bates&#8217; <a title="learn rails videos" href="http://railscasts.com/">Railcasts</a>, you should be.</p>
<p>I follow a variey of rails blogs and lean on a number of resources quite regularly, but the Railscasts are consistently the most useful.  There are now over 100 railscast, each one a roughly 5 minute screencast outlining the solution to some problem.</p>
<p>A recent cast showed how to <a title="rails site wide announcement" href="http://railscasts.com/episodes/103">create a site wide announcement</a> that each user could mark as read individually.  This is a great, non-intrusive way to communicate notices with users.</p>
<p>The screencast details how to do it.  I was able to implement this on a site in a very short period of time.  I made some modifications which make it work better within my site.  I do have one suggestion to improve it overall.  To track whether a message had been read/should be shown Ryan uses the session.  Sessions expire in the near future, and if using a db store, should be wiped daily.  If your users don&#8217;t visit daily, you will want to create a message that hangs around for a week or 2.  In this case, a session variable won&#8217;t work.  Instead, you can store the info in a cookie and set a delayed expire time on it.  (By default, cookies expire with the session in rails).</p>
<p>Before reading how to store this info in a cookie you should watch the screencast.  Once you&#8217;ve implemented everything like Ryan&#8217;s demo, there are just 3 small changes to use cookies and hence have a longer memory.</p>
<p>1. In your controller, set the cookie:</p>
<pre><code class="ruby">
def hide_announcement
  cookies[:announcement_hide_time] ={ :value =&gt; Time.now.to_s , :expires =&gt; 2.weeks.from_now }
end
</code>
</pre>
<p>2. In your helper method, read the value from the cookie.</p>
<pre><code class="ruby">
def current_announcements
  @announcements ||= Announcement.current_announcements(cookies[:announcement_hide_time])
end
</code>
</pre>
<p>3. In the announcement controller you need to parse the time since it is stored as a string in the cookie</p>
<pre><code class="ruby">
def self.current_announcements(hide_time)
  with_scope :find =&gt; { :conditions =&gt; "starts_at &lt;= now() AND ends_at &gt;= now()" } do
    if hide_time
      time = Time.parse(hide_time)
      find(:all, :conditions =&gt; ["updated_at &gt;= ?", time])
    else
      find(:all)
    end
  end
end
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://geoff.evason.name/2008/05/27/railscasts-does-it-again-site-wide-announcements/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

