<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>SamPohlenz.com</title>
    <description>Blog</description>
    <link>http://www.sampohlenz.com/</link>
    <atom:link type="application/rss+xml" href="http://www.sampohlenz.com//feed.xml" rel="self"/>
    <item>
      <title>Quickly disable Rails view sections</title>
      <author>sam@sampohlenz.com (Sam Pohlenz)</author>
      <pubDate>Wed Nov 19 15:21:00 -0800 2008</pubDate>
      <description>
        <![CDATA[<style type="text/css">.align-left { float: left; margin: 0 1em 1em 0; } .align-right { float: right; margin: 0 0 1em 1em; }</style><p>Here's a quick snippet I use for quickly disabling chunks of view code.</p>
<p>
<script src="http://gist.github.com/26736.js" type="text/javascript"></script>
</p>
<p>To use this, just drop the following into your application helper:</p>
<p>
<script src="http://gist.github.com/26737.js" type="text/javascript"></script>
</p>
<p>Of course, you could just surround your code with <code>&lt;% if false %&gt;&lt;% end %&gt;</code> but I think using this simple helper makes the intent slightly clearer.</p>]]>
      </description>
      <link>http://www.sampohlenz.com/2008/11/quickly-disable-rails-view-sections</link>
      <guid>http://www.sampohlenz.com/2008/11/quickly-disable-rails-view-sections</guid>
    </item>
    <item>
      <title>A new pattern for RESTful Rails controllers</title>
      <author>sam@sampohlenz.com (Sam Pohlenz)</author>
      <pubDate>Sun Nov 16 15:20:00 -0800 2008</pubDate>
      <description>
        <![CDATA[<style type="text/css">.align-left { float: left; margin: 0 1em 1em 0; } .align-right { float: right; margin: 0 0 1em 1em; }</style><p>The generally accepted pattern for the new/create actions of RESTful Rails controllers goes something like this (using Recipes as the model):</p>
<p>
<script src="http://gist.github.com/25582.js" type="text/javascript"></script>
</p>
<p>The actions for edit/update are fairly similar so I won't show them here. I've also ignored XML responses as they aren't relevant here.</p>
<p>So what is wrong with this? Lets imagine we're filling out the new recipe form, hence our current path looks like /recipes/new. The form is then posted to /recipes and the @recipe.save call fails due to validation errors in our Recipe model. What is the current path now?</p>
<p>Where we end up is viewing the same form previously accessed at /recipes/new, but now at the path /recipes. Having two URLs accessing the same view, whilst not a major cause for alarm, emits an unpleasant odor.</p>
<p>In recent projects, I have taken to the following alternative pattern:</p>
<p>
<script src="http://gist.github.com/25583.js" type="text/javascript"></script>
</p>
<p>The changes are small but we are now using the session to store the invalid object. If the object fails to save, we redirect back to the new recipe form (at the correct path /recipes/new), which attempts to load the recipe from the session, otherwise defaulting to the original behavior.</p>
<p>Using the session in this way has one big drawback -- we can no longer reliably use the default Rails cookie session store. There are two main reasons for this: a) Cookie stores have a storage limit of 4k, which can easily be reached when storing large objects in the session -- you'll end up with CookieOverflow exceptions being thrown; and b) Saving an object in the cookie store sends the entire object to the client, potentially exposing hidden data. Because of this, I choose to use the memcached session store (which is almost trivially easy to set up unless you're on a shared host).</p>
<p>This approach also appears to add some complexity, but in some ways its behavior is clearer. Consider the case in the original example where we want to add an error message to the flash:</p>
<p>
<script src="http://gist.github.com/25578.js" type="text/javascript"></script>
</p>
<p>BZZZT! What we actually need to use here is flash.now[:error] rather than flash[:error] because we want to render the error within the same action. This gotcha doesn't exist in my alternative version.</p>
<p>So what do you think? Are there any use cases apart from those mentioned where this is either going to fail or cause security issues? Is it even worth using this pattern to fix the original problem, despite the caveats? I think so but I'm willing to be proven wrong.</p>]]>
      </description>
      <link>http://www.sampohlenz.com/2008/11/a-new-pattern-for-restful-rails-controllers</link>
      <guid>http://www.sampohlenz.com/2008/11/a-new-pattern-for-restful-rails-controllers</guid>
    </item>
    <item>
      <title>Rails deployment checklist</title>
      <author>sam@sampohlenz.com (Sam Pohlenz)</author>
      <pubDate>Thu May 15 15:19:00 -0700 2008</pubDate>
      <description>
        <![CDATA[<style type="text/css">.align-left { float: left; margin: 0 1em 1em 0; } .align-right { float: right; margin: 0 0 1em 1em; }</style><p>At Good Dog Design, we manage a number of servers for our clients, and are frequently adding new ones. Whilst this process should really be scripted, until we do, this checklist should help cut a lot of the time that goes into setting up a new server.</p>
<p>These checklists are somewhat debian specific as we mainly run debian and ubuntu servers (on <a href="http://slicehost.com/">Slicehost</a> if you&rsquo;re curious), but many of the points can easily be adapted for your distro of choice.</p>
<h4>Core server setup</h4>
<ul>
<li>Reset root password</li>
<li>Add a normal privilege (non-root) user <code>sudo adduser {username}</code></li>
<li>Add this user to sudoers <code>visudo</code></li>
<li>Login with this user</li>
<li>Ensure all relevant security/update repositories are present in <code>/etc/apt/sources.list</code></li>
<li>Ensure all packages are up to date <code>sudo apt-get update; sudo apt-get upgrade</code>. If any packages are kept back, install them individually <code>sudo apt-get install {package-names}</code>.</li>
<li>Install and configure a firewall <code>sudo apt-get install shorewall</code> (see configuration at <a href="http://blog.matid.net/2007/2/1/securing-your-ubuntu-server">http://blog.matid.net/2007/2/1/securing-your-ubuntu-server</a> [default config is located at <code>/usr/share/doc/shorewall-common/default-config/</code>]</li>
<li>Install essential build tools <code>sudo apt-get install build-essential</code></li>
</ul>
<h4>Services setup</h4>
<ul>
<li>Install git <code>sudo apt-get install git-core</code> or subversion <code>sudo apt-get install subversion</code></li>
<li>Install ruby <code>sudo apt-get install ruby irb ri rdoc ruby1.8-dev libopenssl-ruby</code></li>
<li>Install rubygems from <a href="http://rubyforge.org/frs/?group_id=126">http://rubyforge.org/frs/?group_id=126</a> (don&rsquo;t use apt-get)</li>
<li>Link gem to gem1.8 <code>sudo ln -s /usr/bin/gem1.8 /usr/bin/gem</code></li>
<li>Install relevant gems <code>sudo gem install rails mongrel mongrel_cluster</code></li>
<li>Install postfix <code>sudo apt-get install postfix</code></li>
<li>Install mysql <code>sudo apt-get install mysql-server mysql-client libmysql-ruby1.8</code></li>
<li>Create a production database and user</li>
<li>Install memcache <code>sudo apt-get install memcached; sudo gem install memcache-client</code></li>
<li>Install apache <code>sudo apt-get install apache2 apache2.2-common apache2-mpm-prefork apache2-utils ssl-cert</code></li>
<li>Enable apache modules <code>sudo a2enmod proxy_balancer; sudo a2enmod proxy_http; sudo a2enmod rewrite; sudo a2enmod deflate</code></li>
<li>Create an apache host config file in <code>/etc/apache2/sites-available</code> and enable it <code>sudo a2ensite {sitename}</code></li>
<li>Create a deploy group <code>sudo groupadd deploy</code> and add any users to this group (<code>sudo adduser {user} deploy</code>)</li>
<li>Create a folder for the project <code>sudo mkdir /var/www/project-url.com; sudo chown {me}:deploy /var/www/project-url.com</code></li>
<li>Create a mongrel user and group <code>sudo useradd mongrel</code> (don&rsquo;t set a password for this user)</li>
<li>Install and configure monit <code>sudo apt-get install monit</code></li>
</ul>
<h4>Rails setup</h4>
<ul>
<li>Capify rails project <code>capify .</code></li>
<li>Install and configure the ExceptionNotifier plugin</li>
<li>Install any app-specific gems</li>
<li>Setup capistrano folder structure <code>cap deploy:setup</code></li>
<li>Cold deploy <code>cap deploy:cold</code></li>
<li>Ensure mongrels are running and site is accessible</li>
<li>Test regular deploys <code>cap deploy</code></li>
<li>Setup any necessary cronjobs (I generally put them into an individual project file in <code>/etc/cron.d/</code>)</li>
<li>Set up log rotation</li>
</ul>]]>
      </description>
      <link>http://www.sampohlenz.com/2008/5/rails-deployment-checklist</link>
      <guid>http://www.sampohlenz.com/2008/5/rails-deployment-checklist</guid>
    </item>
    <item>
      <title>That new blog smell</title>
      <author>sam@sampohlenz.com (Sam Pohlenz)</author>
      <pubDate>Tue Apr 29 15:18:00 -0700 2008</pubDate>
      <description>
        <![CDATA[<style type="text/css">.align-left { float: left; margin: 0 1em 1em 0; } .align-right { float: right; margin: 0 0 1em 1em; }</style><p>After a long time away from the keyboard (so to speak), its about time I started blogging again!</p>
<p>Since I last blogged, I&rsquo;ve completed my honours degree in Computer Science at the University of Adelaide and am now working for <a href="http://www.gooddogdesign.com/">Good Dog Design</a> in Mill Valley (about 15-20 minutes drive north of San Francisco).</p>
<p>This site is under development at the moment but it should be up and running very soon. My intentions are to blog about web dev related topics (Ruby, Javascript, etc.) and whatever else takes my fancy.</p>
<p>Enjoy.</p>]]>
      </description>
      <link>http://www.sampohlenz.com/2008/4/that-new-blog-smell</link>
      <guid>http://www.sampohlenz.com/2008/4/that-new-blog-smell</guid>
    </item>
  </channel>
</rss>
