<?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>Nate Miller &#187; Ruby on Rails</title>
	<atom:link href="http://www.natemiller.org/category/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.natemiller.org</link>
	<description>Waxing poetic about the internet</description>
	<lastBuildDate>Fri, 19 Mar 2010 22:07:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Sync a database with Capistrano</title>
		<link>http://www.natemiller.org/2009/10/11/sync-a-remote-database-to-local-with-capistrano/</link>
		<comments>http://www.natemiller.org/2009/10/11/sync-a-remote-database-to-local-with-capistrano/#comments</comments>
		<pubDate>Sun, 11 Oct 2009 08:53:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Featured Articles]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.natemiller.org/?p=78</guid>
		<description><![CDATA[A quick capistrano task for synchronizing a remote database to your local development environment]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a quick capistrano task for synchronizing a remote database to your local development environment:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">&nbsp;
set <span style="color:#ff3333; font-weight:bold;">:application</span>, <span style="color:#996600;">&quot;appname&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:application_path</span>, <span style="color:#996600;">&quot;/home/someurl/apps&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:user</span>, <span style="color:#996600;">&quot;appuser&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:password</span>, <span style="color:#996600;">&quot;***********&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:use_sudo</span>, <span style="color:#0000FF; font-weight:bold;">false</span>
&nbsp;
set <span style="color:#ff3333; font-weight:bold;">:production_database</span>,<span style="color:#996600;">'mydb_production'</span>
set <span style="color:#ff3333; font-weight:bold;">:production_dbhost</span>, <span style="color:#996600;">'localhost'</span>
set <span style="color:#ff3333; font-weight:bold;">:dbuser</span>, <span style="color:#996600;">'dbadmin'</span>
set <span style="color:#ff3333; font-weight:bold;">:dbpass</span>, <span style="color:#996600;">'************'</span>
&nbsp;
desc <span style="color:#996600;">&quot;Synchronizes remote database to local development database&quot;</span>
task <span style="color:#ff3333; font-weight:bold;">:sync_to_local</span>, <span style="color:#ff3333; font-weight:bold;">:roles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:web</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    sql_out = <span style="color:#996600;">&quot;#{environment_database}.sql&quot;</span>
    run <span style="color:#996600;">&quot;mysqldump --user #{dbuser} --password=#{dbpass} #{environment_database} &gt; #{sql_out}&quot;</span>
    <span style="color:#CC0066; font-weight:bold;">system</span> <span style="color:#996600;">&quot;sftp #{user}@mywebserver.com:#{sql_out} /tmp/#{sql_out}&quot;</span>
    run <span style="color:#996600;">&quot;rm #{sql_out}&quot;</span>
    <span style="color:#CC0066; font-weight:bold;">system</span> <span style="color:#996600;">&quot;mysql -u #{dbuser} --password=#{dbpass} somedatabase_development &lt; /tmp/#{sql_out}&quot;</span>
    <span style="color:#CC0066; font-weight:bold;">system</span> <span style="color:#996600;">&quot;rm /tmp/#{sql_out}&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.natemiller.org/2009/10/11/sync-a-remote-database-to-local-with-capistrano/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Painless db backups in Rails</title>
		<link>http://www.natemiller.org/2009/10/10/create-a-database-backup-with-rails/</link>
		<comments>http://www.natemiller.org/2009/10/10/create-a-database-backup-with-rails/#comments</comments>
		<pubDate>Sat, 10 Oct 2009 08:00:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Featured Articles]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://dev.natemiller.org/?p=3</guid>
		<description><![CDATA[A simple way to automate the generation of a MySQL database backup.]]></description>
			<content:encoded><![CDATA[<p>Quite often in Rails projects, I need some way to backup the contents of database quickly. The script below is an easy way to backup the database of your current environment using the database.yml file already set up in your Rails project. Feel free to modify the below script to do your bidding.</p>
<p>/script/backup_db:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#!/usr/bin/env ruby</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">dirname</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">'/../config/boot'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'erb'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'yaml'</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">unless</span> config = <span style="color:#CC00FF; font-weight:bold;">YAML</span>::<span style="color:#CC0066; font-weight:bold;">load</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">ERB</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">IO</span>.<span style="color:#9900CC;">read</span><span style="color:#006600; font-weight:bold;">&#40;</span>RAILS_ROOT <span style="color:#006600; font-weight:bold;">+</span>
<span style="color:#996600;">&quot;/config/database.yml&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">result</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span>RAILS_ENV<span style="color:#006600; font-weight:bold;">&#93;</span>
   abort <span style="color:#996600;">&quot;No database found for environment '#{RAILS_ENV}'&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
db_out_path = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span>RAILS_ROOT, <span style="color:#996600;">'tmp'</span>, <span style="color:#996600;">&quot;dbdump_#{RAILS_ENV}.sql&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#CC0066; font-weight:bold;">system</span> <span style="color:#996600;">&quot;mysqldump -u #{config['username']} --password=#{config['password']}
 #{config['database']} &gt;; #{db_out_path}&quot;</span></pre></div></div>

<p>To run your backup, just execute this from your rails root:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">script<span style="color:#006600; font-weight:bold;">/</span>backup_db RAILS_ENV=production</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.natemiller.org/2009/10/10/create-a-database-backup-with-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automated image sharpening</title>
		<link>http://www.natemiller.org/2009/02/28/automated-image-sharpening/</link>
		<comments>http://www.natemiller.org/2009/02/28/automated-image-sharpening/#comments</comments>
		<pubDate>Sat, 28 Feb 2009 18:41:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Featured Articles]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://dev.natemiller.org/?p=28</guid>
		<description><![CDATA[An easy way to automate image sharpening for photos uploaded into Ruby on Rails. This article discusses how to set up Paperclip and ImageMagick to unsharpen your photos automatically.]]></description>
			<content:encoded><![CDATA[<h2>The Problem</h2>
<p>Working in an agency setting, where the crispness and clarity of your images is extremely important, writing web systems that automatically generate thumbnails can be problematic. When resizing images downwards, as is often the case in thumbnail generation, pixel values are approximated from their original size. These approximations can result in thumbnail images which are blurry and difficult to read. The bigger the change in pixel size, the more dramatic the effect. So if you resize a 900&#215;900px image into 120&#215;120, you will see a major difference in clarity.</p>
<p>Photoshop has several methods for dealing with these approximations when resizing images &#8211; namely the Bicubic Sharpening interpolation method and the Unsharp filter. Both of these methods help improve image quality when resizing downwards.</p>
<p>The best way to see what I&#8217;m describing is through example:</p>
<div id="attachment_38" class="wp-caption alignnone" style="width: 455px"><img class="size-full wp-image-38" title="sharpening_example" src="http://www.natemiller.org/wp-content/uploads/2009/10/sharpening_example.jpg" alt="Example of image sharpening in action" width="445" height="263" /><p class="wp-caption-text">Example of image sharpening in action</p></div>
<p>If we rely on out-of-the-box image resizing methods typically available, we usually end up with thumbnails that look like the upper right photo: blurry and unclear. However, we can easily have our applications automatically apply an unsharpening mask when we generate thumbnails. For instance a common image library used in online applications is ImageMagick &#8211; which has all sorts of features which can help our images maintain quality at smaller sizes.</p>
<p>In a recent project, I was tasked with creating a portfolio system which would be used to showcase work. The requirements were that the system should upload an image file and automatically generate several sizes of thumbnails to be used throughout the website. However, the thumbnails need to have the same crispness of their original full-size counterparts.</p>
<h2>The Solution</h2>
<p>The solution is in fact amazingly simple. Here are some quick assumptions:</p>
<ul>
<li>The platform where we&#8217;re running our web app has &#8220;ImageMagick&#8221;:http://www.imagemagick.org/script/index.php installed</li>
<li> We&#8217;re using the &#8220;Papercilp&#8221;:http://www.thoughtbot.com/projects/paperclip plugin to handle uploading and thumbnail processing</li>
</ul>
<p>Here&#8217;s the code we place at the top of our model which will be responsible for accepting uploaded photos:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Project <span style="color:#006600; font-weight:bold;">&amp;</span>lt; <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
   has_attached_file <span style="color:#ff3333; font-weight:bold;">:hero_shot</span>,
     <span style="color:#ff3333; font-weight:bold;">:styles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:large</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">&quot;500x500&quot;</span>,
     <span style="color:#ff3333; font-weight:bold;">:medium</span> <span style="color:#006600; font-weight:bold;">=&gt;</span>; <span style="color:#996600;">&quot;300x300&amp;gt;&quot;</span>,
     <span style="color:#ff3333; font-weight:bold;">:thumb</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;100x100&amp;gt;&quot;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>,
     <span style="color:#ff3333; font-weight:bold;">:convert_options</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:all</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;-unsharp 0.3x0.3+5+0&quot;</span> <span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

<p>With the above declaration in our model, Paperclip will create 3 thumbnails in 3 different sizes. The :convert_options hash is where we define how the photo will be processed and is responsible for performing the unsharpening. Passing the :convert_options hash allows us to specify specific instructions to ImageMagick &#8211; just like if we were using the ImageMagick library from the command line. Let&#8217;s take a look at the code which provides the unsharpening:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">-</span>unsharp 0.3x0.3<span style="color:#006600; font-weight:bold;">+</span><span style="color:#006666;">5</span><span style="color:#006600; font-weight:bold;">+</span><span style="color:#006666;">0</span></pre></div></div>

<p>So where did we come up with this strange looking command? Essentially this is the same as executing &#8220;convert -unsharp 0.3&#215;0.3+5+0 IMAGE.jpg NEW_IMAGE.jpg&#8221; from the command line. The :convert_options hash is basically a list of parameters that Paperclip will be passing to the ImageMagick &#8220;convert&#8221; command. The command above is telling ImageMagick to unsharpen each of our photos. If you want a more detailed explanation, please see <a href="http://redskiesatnight.com/2005/04/06/sharpening-using-image-magick/">this great blog post</a> about fine-tuning this command. As is shown here, this command is performing an unsharp mask of a radius of 0.3 pixels, with an amount of 5.0 applied to it (in relation to the Photoshop effect, this is equivalent to an amount value of 500% at 0.3 pixel radius).</p>
<p>That&#8217;s it &#8211; now when we upload a photo, Paperclip will automatically resize and unsharpen our photos. The result is thumbnail photos which are more clear and truer to the original image.</p>
<h3>Resources</h3>
<ul>
<li><a href="http://www.thoughtbot.com/projects/paperclip">Paperclip plugin/gem</a></li>
<li><a href="http://railscasts.com/episodes/134-paperclip">Railscasts &#8211; Paperclip</a></li>
<li><a href="http://redskiesatnight.com/2005/04/06/sharpening-using-image-magick/">Unsharpening with ImageMagick</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.natemiller.org/2009/02/28/automated-image-sharpening/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>5 Reasons to Use Rails</title>
		<link>http://www.natemiller.org/2009/02/22/5-reasons-to-use-rails/</link>
		<comments>http://www.natemiller.org/2009/02/22/5-reasons-to-use-rails/#comments</comments>
		<pubDate>Sun, 22 Feb 2009 18:48:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://dev.natemiller.org/?p=49</guid>
		<description><![CDATA[One axiom overheard constantly throughout the blogs and forums of the internet&#8217;s technorati, is &#8220;use the right tool for the job.&#8221; Generally this nugget is brought up in conversations questioning whether one should use framework A or framework B, language C or language D, etc&#8230; Invariably, people get pissed, comments get ridiculous, and &#8220;that guy&#8221;:http://www.geekitude.com/Pictures/Linucon2004/Ex45TronUpCloseRot.jpg [...]]]></description>
			<content:encoded><![CDATA[<p>One axiom overheard constantly throughout the blogs and forums of the internet&#8217;s technorati, is &#8220;use the right tool for the job.&#8221; Generally this nugget is brought up in conversations questioning whether one should use framework A or framework B, language C or language D, etc&#8230; Invariably, people get pissed, comments get ridiculous, and &#8220;that guy&#8221;:http://www.geekitude.com/Pictures/Linucon2004/Ex45TronUpCloseRot.jpg eventually shows up to tell everyone that they&#8217;re retards for not using Lisp. This is not one of those articles. Having spent too much of my life reading those posts, trying to decipher if tool A is right for feature-that-needs-to-go-live-next-week-or-else-you&#8217;ll-be-replaced-by-10-indian-programmers, I&#8217;ve decided to write up some reasons why you just may want to consider to start using Rails.</p>
<p>Before going much further, I should state that I enjoy programming just about anything and in about any language. A good weekend for me almost always includes compilation of source code and a strong beer–the order and frequency of the two being highly dependent on the preceding 5 days. But take my opinions with a grain of salt. These opinions are from a geek working in the ad world where development cycles are extremely tiny and our requirement list is often very different from software development studios.</p>
<h3>1. Rails deployment are now almost as easy as PHP deployments</h3>
<p>It used to be that Rails&#8217; biggest hurdle was deployment. Having set up many mongrel-based deployment schemes, I can understand why Rails scared away a lot of people. However, with stability of &#8220;Phusion Passenger&#8221;:http://www.modrails.com/, setting up a Rails app is now just as trivial as PHP. If you&#8217;re worried about stability, it may be worth it to know there are a handful of large websites now using Passenger, including &#8220;Shopify&#8221;:http://www.shopify.com and even &#8220;NY Times&#8221;:http://www.nytimes.com. We deploy all of our Rails sites through Passenger and have not had one major problem yet.</p>
<h3>2. Test like a pro</h3>
<p>If you enjoy working within the MVC paradigm and you feel guilty about writing code before you write a test, Rails provides a wealth of features proven in the .NET and Java enterprise landscape, and adapts them to the flexible Ruby language. Test and Behavior driven development approaches are easy to follow in Rails.</p>
<h3>3. You want easy object relational mapping</h3>
<p>ActiveRecord is a thing of beauty. Does it work for every possible situation? Nope, but it gets you pretty darn close. The first time I made a database query in Rails, my jaw dropped.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">User.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:all</span>, <span style="color:#ff3333; font-weight:bold;">:conditions</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#006600; font-weight:bold;">&#91;</span> <span style="color:#996600;">'created_at &amp;lt; ?'</span>, <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span> <span style="color:#006600; font-weight:bold;">-</span> 1.<span style="color:#9900CC;">days</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>Even if you haven&#8217;t used Rails before, what that tiny command does is probably pretty obvious. While ActiveRecord is not an excuse for any developer to forget SQL entirely, it helps us with the low hanging fruit in our systems and lets us spend more time where we should really be using our brains.</p>
<h3>4. You&#8217;re really tired of FTP</h3>
<p>I have a confession &#8211; you don&#8217;t need to use Rails to take advantage of automated deployments with the amazing &#8220;Capistrano&#8221;:http://www.capify.org/ tool. Launching new deployments of client websites is now as easy as executing the following command from the command line:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">cap production deploy</pre></div></div>

<p>This line, after some configuration of course, will completely deploy my application from a repository, run any database migrations, reset my daemons, and keep a copy of the last version in case something is botched. Rolling back is easy:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">cap production deploy:rollback</pre></div></div>

<p>Boom! I&#8217;m right back to the last version before the client even saw the nasty 500 error header on their contact page. Whew! (Not that this ever happens of course&#8230;eh-hem).</p>
<h3>5. You want easier maintainability</h3>
<p>There is no such thing as a sealed class in Ruby. That means if I don&#8217;t like Ruby&#8217;s String class, I can easily rewrite it to suit my needs (otherwise known as *monkey-patching*) at any time throughout a program&#8217;s execution. This is both very dangerous and a very awesome for some fairly obvious reasons. If we have interoperability between 2 different software libraries, we can easily patch the deficiencies ourselves while keeping the original libraries intact. If you don&#8217;t like how Rails handles error messages, you can easily override the offending method or patch the functionality how you see fit.</p>
<p>Is this approach to software development raising some red flags? It should, but there&#8217;s a way to make ourselves feel better. With a strong system of unit tests in place, we give ourselves an easy way to assure that functionality remains unchanged when software updates roll out, or requirements of a component change. While the dynamic aspects of Ruby can cause us some serious headaches if we abuse this power, we can save ourselves significant work by writing small patches instead of modifying many different source files.</p>
<h2>Conclusion</h2>
<p>I talked about a lot of different things, and admittedly, didn&#8217;t go into a lot of depth. But if you&#8217;re curious about what it&#8217;s like to develop in Rails, check out some of the things I&#8217;ve pointed out above. For me, these 5 points have made Rails my preferred web platform of choice for small to medium-sized, database driven websites.5</p>
]]></content:encoded>
			<wfw:commentRss>http://www.natemiller.org/2009/02/22/5-reasons-to-use-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

