<?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>Burm.net &#187; RoR</title>
	<atom:link href="http://burm.net/tag/ror/feed/" rel="self" type="application/rss+xml" />
	<link>http://burm.net</link>
	<description>John Burmeister's Blog</description>
	<lastBuildDate>Tue, 31 Jan 2012 03:31:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Ruby on Rails Best Coding Practices Slide Show and Gem</title>
		<link>http://burm.net/2009/11/17/rails-best-coding-practices-slide-show-and-gem/</link>
		<comments>http://burm.net/2009/11/17/rails-best-coding-practices-slide-show-and-gem/#comments</comments>
		<pubDate>Wed, 18 Nov 2009 01:54:39 +0000</pubDate>
		<dc:creator>John Burmeister</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Rails Plugins]]></category>
		<category><![CDATA[Rails Tutorials]]></category>
		<category><![CDATA[RoR]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://burm.net/?p=249</guid>
		<description><![CDATA[When browsing around today I saw quite a few sites talking about the Rails Best Practices presentation / talk that ihower did at the Kungfu RailsConf. Check it below, it really covers a lot of basic tips on how to clean up your code and follow some better coding practices. Someone just released a gem [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fburm.net%2F2009%2F11%2F17%2Frails-best-coding-practices-slide-show-and-gem%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fburm.net%2F2009%2F11%2F17%2Frails-best-coding-practices-slide-show-and-gem%2F&amp;source=burmjohn&amp;style=compact&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>When browsing around today I saw quite a few sites talking about the Rails Best Practices presentation / talk that ihower did at the Kungfu RailsConf. Check it below, it really covers a lot of basic tips on how to clean up your code and follow some better coding practices.</p>
<p>Someone just released a gem that will analyze your code and check for &#8220;Best Practices&#8221; -  seems promising. Check it out at GitHub here: <a href="http://github.com/flyerhzm/rails_best_practices">http://github.com/flyerhzm/rails_best_practices</a></p>
<div id="__ss_2334123" style="width: 425px; text-align: left;"><object style="margin:0px" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=rails-best-practices-091024015011-phpapp01&amp;stripped_title=rails-best-practices" /><param name="allowfullscreen" value="true" /><embed style="margin:0px" type="application/x-shockwave-flash" width="425" height="355" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=rails-best-practices-091024015011-phpapp01&amp;stripped_title=rails-best-practices" allowscriptaccess="always" allowfullscreen="true"></embed></object></div>
]]></content:encoded>
			<wfw:commentRss>http://burm.net/2009/11/17/rails-best-coding-practices-slide-show-and-gem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails Rumble 2008 App List</title>
		<link>http://burm.net/2008/10/19/rails-rumble-2008-app-list/</link>
		<comments>http://burm.net/2008/10/19/rails-rumble-2008-app-list/#comments</comments>
		<pubDate>Mon, 20 Oct 2008 00:55:07 +0000</pubDate>
		<dc:creator>John Burmeister</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[RoR]]></category>

		<guid isPermaLink="false">http://burm.net/?p=159</guid>
		<description><![CDATA[Put together a small list of apps I saw today that are part of the Rails Rumble 2008. Let me know if I missed any by adding a comment.  Check out http://blog.railsrumble.com/ &#8211; I am sure they will post an official list shortly. *** The list keeps growing! http://meetinbetween.us/ &#8211; Car pooling site http://tunemuncher.com/ &#8211; Music [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fburm.net%2F2008%2F10%2F19%2Frails-rumble-2008-app-list%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fburm.net%2F2008%2F10%2F19%2Frails-rumble-2008-app-list%2F&amp;source=burmjohn&amp;style=compact&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Put together a small list of apps I saw today that are part of the Rails Rumble 2008.</p>
<p><a href="http://burm.net/wp-content/uploads/2008/10/railsrumblebadge_90_1.png"><img class="alignright size-medium wp-image-160" title="railsrumblebadge_90_1" src="http://burm.net/wp-content/uploads/2008/10/railsrumblebadge_90_1.png" alt="" width="90" height="90" /></a></p>
<p>Let me know if I missed any by adding a comment.  Check out <a href="http://blog.railsrumble.com/">http://blog.railsrumble.com/</a> &#8211; I am sure they will post an official list shortly.</p>
<p>*** The list keeps growing!</p>
<p><a href="http://meetinbetween.us/">http://meetinbetween.us/</a> &#8211; Car pooling site</p>
<p><a href="http://tunemuncher.com/">http://tunemuncher.com/</a> &#8211; Music artist tracking site, shows latest ablums from artists you like.</p>
<p><a href="http://wurbe.r08.railsrumble.com/">http://wurbe.r08.railsrumble.com/</a> &#8211; Conference organization?</p>
<p><a href="http://foodferret.com/">http://foodferret.com/</a> &#8211; A service that finds the right food for you?</p>
<p><a href="http://likis.r08.railsrumble.com/">http://likis.r08.railsrumble.com/</a> &#8211; Social language learning</p>
<p><a href="http://chicago.r08.railsrumble.com/">http://chicago.r08.railsrumble.com/</a> &#8211; Simple presentations</p>
<p><a href="http://so2speak.net">http://so2speak.net</a> &#8211; RSS / Webservices to speach</p>
<p><a href="http://wethepeople.r08.railsrumble.com/">http://wethepeople.r08.railsrumble.com/</a> &#8211; Political news?</p>
<p><a href="http://myideadrawer.r08.railsrumble.com/">http://myideadrawer.r08.railsrumble.com</a>/ - Organize, collect, and share your projects</p>
<p><a href="http://pug.r08.railsrumble.com/">http://pug.r08.railsrumble.com/</a> &#8211; Pickup game locator</p>
<p><a href="http://a8.r08.railsrumble.com/">http://a8.r08.railsrumble.com/</a> &#8211; A solution for managing projects from proposal, through build stage, to getting paid.</p>
<p><a href="http://dontsendit.r08.railsrumble.com/">http://dontsendit.r08.railsrumble.com/</a> &#8211; Delayed email sending?</p>
<p><a href="http://maestro.r08.railsrumble.com/">http://maestro.r08.railsrumble.com</a>/ &#8211; Music Create / Sharing app</p>
<p><a href="http://notifly.r08.railsrumble.com/">http://notifly.r08.railsrumble.com/</a> - Easily integrate communication services into your app</p>
<p><a href="http://jotlyapp.com/">http://jotlyapp.com</a>/ &#8211; Blogging app</p>
<p><a href="http://run1mile.com">http://run1mile.com</a> &#8211; A program to get your from nothing to running one mile</p>
<p><a href="http://iheartgames.r08.railsrumble.com/">http://iheartgames.r08.railsrumble.com/</a> &#8211; A social application where you list your games and connect with your friends to play games.</p>
<p><a href="http://billelle.r08.railsrumble.com">http://billelle.r08.railsrumble.com</a> &#8211; Unknown</p>
<p><a href="http://greatminds.r08.railsrumble.com/">http://greatminds.r08.railsrumble.com/</a> &#8211; A co-operative word game for two or more players</p>
<p><a href="http://www.loveloathe.com/">http://www.loveloathe.com/</a> &#8211; Lists of things you love and hate.</p>
<p><a href="http://poolr.r08.railsrumble.com/">http://poolr.r08.railsrumble.com/</a> &#8211; Find a car pool</p>
<p><a href="http://sellyourattention.r08.railsrumble.com">http://sellyourattention.r08.railsrumble.com</a>/ &#8211; Build a potato man</p>
<p><a href="http://gtd.r08.railsrumble.com/">http://gtd.r08.railsrumble.com/</a> &#8211;  task / GTD app</p>
<p><a href="http://twalala.com">http://twalala.com</a> &#8211; Web based twitter client</p>
<p><a href="http://hikedit.r08.railsrumble.com/">http://hikedit.r08.railsrumble.com/</a> &#8211; Hiking fan site, find trails</p>
<p><a href="http://stickyboard.r08.railsrumble.com/">http://stickyboard.r08.railsrumble.com/</a> &#8211; No idea what this is &#8211; a wall of randomness?</p>
<p><a href="http://milliontagcloud.r08.railsrumble.com/">http://milliontagcloud.r08.railsrumble.com/</a> &#8211; donation app</p>
<p><a href="http://osc.r08.railsrumble.com">http://osc.r08.railsrumble.com</a>/ &#8211; Treasuring hunting w/SMS</p>
<p><a href="http://foodistic.com">http://foodistic.com</a> &#8211; Track what you eat</p>
<p><a href="http://www.playubetcha.com">http://www.playubetcha.com/</a> - online game where you can wager points on real-world events</p>
<p><a href="http://storyseed.r08.railsrumble.com/">http://storyseed.r08.railsrumble.com/</a> &#8211; create, publish, read and rate stories</p>
<p><a href="http://citenow.r08.railsrumble.com/">http://citenow.r08.railsrumble.com/</a> &#8211; Keeps track of your citations on books, journals and websites.</p>
<p><a href="http://rio.r08.railsrumble.com">http://rio.r08.railsrumble.com</a>/ &#8211; pics of your diet (food)</p>
<p><a href="http://goodbad.me/">http://goodbad.me/</a> - see all the good and bad stuff in the Twitterverse</p>
<p><a href="http://inspiresme.r08.railsrumble.com/home ">http://inspiresme.r08.railsrumble.com/home </a>-  say who inspirse you</p>
<p><a href="http://pranziamo.r08.railsrumble.com/">http://pranziamo.r08.railsrumble.com/</a> - Lunch recommendations</p>
<p><a href="http://diedebtdie.r08.railsrumble.com/">http://diedebtdie.r08.railsrumble.com/</a> &#8211; provides you with tools and motivation to get you out of the red…and back in the black.</p>
<p><a rel="nofollow" href="http://qflip.r08.railsrumble.com/">http://qflip.r08.railsrumble.com/</a> &#8211; Qflip is an app that integrates with the netflix api that helps people to rent randomly.</p>
<p><a rel="nofollow" href="http://couldya.r08.railsrumble.com/">http://couldya.r08.railsrumble.com/</a> &#8211; Its a way to get help with things using your social network.</p>
<p><a rel="nofollow" href="http://ir.r08.railsrumble.com/">http://ir.r08.railsrumble.com/</a> -Latte Art with ratings</p>
<p><a rel="nofollow" href="http://ideasftw.com/">http://ideasftw.com</a> &#8211; An idea incubator.</p>
<p><a href="http://sheepfit.r08.railsrumble.com/">http://sheepfit.r08.railsrumble.com/</a> &#8211; a stretch reminder</p>
<p><a rel="nofollow" href="http://www.rubyreddo.com/">http://www.rubyreddo.com</a> &#8211; RubyReddo is a service to translate your GetText .po files</p>
<p><a href="http://justafinlist.r08.railsrumble.com/">http://justafinlist.r08.railsrumble.com/</a> &#8211; Just A F***ing List</p>
<p><a rel="nofollow" href="http://dense.r08.railsrumble.com/">http://dense.r08.railsrumble.com/</a> &#8211; Dense is a simple slideshop app</p>
<p><a rel="nofollow" href="http://remindr.info/">http://remindr.info</a> &#8211; Effortless one-click reminder about pretty much anything</p>
<p><a rel="nofollow" href="http://ostraka.r08.railsrumble.com/">http://ostraka.r08.railsrumble.com/</a> &#8211; Ostraka is the digital counterpart of ancient democratic instrument of ostracism.</p>
<p><a rel="nofollow" href="http://tagueame.r08.railsrumble.com/">http://tagueame.r08.railsrumble.com/</a> &#8211; Tagueame is a little experiment about socializing online opinions about your friends and family.</p>
<p><a href="http://a8.r08.railsrumble.com/" target="_blank">http://a8.r08.railsrumble.com/</a> &#8211; A business related app for project management, time reporting, invoicing with built in chat rooms.</p>
<p><a href="http://wheresthemilkat.r08.railsrumble.com/">http://wheresthemilkat.r08.railsrumble.com/</a> &#8211;   find out who’s got the best prices, and where they are</p>
<p><a rel="nofollow" href="http://ndebted.com/">http://ndebted.com</a> &#8211; A service for tracking and sharing debts with friends</p>
<p><a rel="nofollow" href="http://assassin.r08.railsrumble.com/">http://assassin.r08.railsrumble.com</a> &#8211; The assassin game</p>
<p>Another great list of Rails Rumble 2008 apps  &#8211; &gt; <a href="http://48hrlaunch.wordpress.com/2008/10/20/rails-rumble-2008-apps/ " target="_blank">http://48hrlaunch.wordpress.com/2008/10/20/rails-rumble-2008-apps/ </a></p>
<p><a rel="nofollow" href="http://revealthebias.r08.railsrumble.com/">http://revealthebias.r08.railsrumble.com/</a> &#8211; Reveal the Bias</p>
]]></content:encoded>
			<wfw:commentRss>http://burm.net/2008/10/19/rails-rumble-2008-app-list/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Rails Rumble 2008 has started</title>
		<link>http://burm.net/2008/10/17/rails-rumble-2008-has-started/</link>
		<comments>http://burm.net/2008/10/17/rails-rumble-2008-has-started/#comments</comments>
		<pubDate>Sat, 18 Oct 2008 03:33:30 +0000</pubDate>
		<dc:creator>John Burmeister</dc:creator>
				<category><![CDATA[Rails Ecommerce Project]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[RoR]]></category>

		<guid isPermaLink="false">http://burm.net/?p=145</guid>
		<description><![CDATA[Just an FYI&#8230; Rails Rumble 2008 has started. I am signed up to be a judge, It would be pretty interesting to see what comes out of this 48 hour hack fest. The Rails Rumble is a 48 hour web application development competition. As a contestant, you get one weekend to design, develop, and deploy [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fburm.net%2F2008%2F10%2F17%2Frails-rumble-2008-has-started%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fburm.net%2F2008%2F10%2F17%2Frails-rumble-2008-has-started%2F&amp;source=burmjohn&amp;style=compact&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Just an FYI&#8230;   <img class="alignright" title="Rails rumble 2008" src="http://blog.railsrumble.com/assets/2008/9/24/RailsRumbleBadge_125_1.png" alt="" width="125" height="125" /></p>
<p><a href="http://railsrumble.com">Rails Rumble 2008</a> has started.  I am signed up to be a judge, It would be pretty interesting to see what comes out of this 48 hour hack fest.</p>
<blockquote><p>The Rails Rumble is a 48 hour web application development competition. As a contestant, you get one weekend to design, develop, and deploy the best web property that you can, using the awesome power of Ruby on Rails</p></blockquote>
<p>Read more about it from their latest blog post: <a href="http://blog.railsrumble.com/2008/10/17/it-s-on">It&#8217;s On!</a></p>
<p>I&#8217;ll try to get a list going of the open source projects that come out of this event, and post the git hub links.</p>
<p>Here is the first app from what someone had posted in IRC: <a href="http://gentrify.r08.railsrumble.com/">http://gentrify.r08.railsrumble.com/ </a>- maybe its something to follow?</p>
<p>**** Update</p>
<p>Links to watch:</p>
<p><a href="http://www.trackclass.com">http://www.trackclass.com</a></p>
<p><a href="http://gentrify.r08.railsrumble.com/">http://gentrify.r08.railsrumble.com/</a></p>
<p><a href="http://li47-127.members.linode.com/">http://li47-127.members.linode.com/</a></p>
<p><a href="http://tweetfu.r08.railsrumble.com/">http://tweetfu.r08.railsrumble.com/</a></p>
<p><a href=" http://chores.r08.railsrumble.com/">http://chores.r08.railsrumble.com/</a></p>
<p><a href="http://laktek.r08.railsrumble.com/">http://laktek.r08.railsrumble.com/</a></p>
<p><a href="http://justafinlist.r08.railsrumble.com/">http://justafinlist.r08.railsrumble.com/</a></p>
<p><a href="http://confreader.r08.railsrumble.com/">http://confreader.r08.railsrumble.com/</a></p>
<p><a href="http://sheepfit.r08.railsrumble.com/">http://sheepfit.r08.railsrumble.com/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://burm.net/2008/10/17/rails-rumble-2008-has-started/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby On Rails Polymorphic Paperclip Plugin Tutorial</title>
		<link>http://burm.net/2008/10/17/ruby-on-rails-polymorphic-paperclip-plugin-tutorial/</link>
		<comments>http://burm.net/2008/10/17/ruby-on-rails-polymorphic-paperclip-plugin-tutorial/#comments</comments>
		<pubDate>Sat, 18 Oct 2008 02:59:48 +0000</pubDate>
		<dc:creator>John Burmeister</dc:creator>
				<category><![CDATA[My Projects]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[paperclip]]></category>
		<category><![CDATA[RoR]]></category>

		<guid isPermaLink="false">http://burm.net/?p=138</guid>
		<description><![CDATA[This tutorial is an extension of the paperclip tutorial I put up last week. This time we are going to take advantage of polymorphic paperclip. Polymorphic paperclip utilizes separate tables (an assets table and an attachings table) to track your attachments. This allows for an unlimited number of attachments per item per model. In the [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fburm.net%2F2008%2F10%2F17%2Fruby-on-rails-polymorphic-paperclip-plugin-tutorial%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fburm.net%2F2008%2F10%2F17%2Fruby-on-rails-polymorphic-paperclip-plugin-tutorial%2F&amp;source=burmjohn&amp;style=compact&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>This tutorial is an extension of the <a href="http://burm.net/2008/10/07/the-ruby-on-rails-paperclip-plugin-tutorial-easy-image-attachments/">paperclip tutorial</a> I put up last week. This time we are going to take advantage of polymorphic paperclip.  Polymorphic paperclip utilizes separate tables (an assets table and an attachings table) to track your attachments.  This allows for an unlimited number of attachments per item per model.  In the first tutorial I showed you how to attach just one item, although you could add more columns to your table to handle additional attachments this way is a lot more flexible.  While this plugin is not perfect, there is a lot of room for improvement, its a great starting point.  Perhaps a fork is on its way from me&#8230; </p>
<p>Project Page: <a href="http://github.com/heavysixer/paperclippolymorph/tree/master">http://github.com/heavysixer/paperclippolymorph/tree/master</a></p>
<p><strong>First things first, lets install the plugin:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;">script<span style="color:#006600; font-weight:bold;">/</span>plugin git:<span style="color:#006600; font-weight:bold;">//</span>github.<span style="color:#9900CC;">com</span><span style="color:#006600; font-weight:bold;">/</span>heavysixer<span style="color:#006600; font-weight:bold;">/</span>paperclippolymorph.<span style="color:#9900CC;">git</span></pre></div></div>

<p>Lets setup our new migration that is needed.  After reading the rdoc, I noticed there was a new generator installed. Great, this makes things even easier.  Lets verify that the generator is available for use, first run:</p>

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

<p>This should produce a list of all generators available for use, my list below might vary from yours depending upon what plugins you have installed&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Installed Generators
  Plugins (vendor/plugins): authenticated, forgot_password, open_id_authentication_tables, paperclip, polymorphic_paperclip, roles, rspec, rspec_controller, rspec_model, rspec_scaffold, upgrade_open_id_authentication_tables
  Builtin: controller, integration_test, mailer, migration, model, observer, plugin, resource, scaffold, session_migration</pre></div></div>

<p>As you will notice there is a polymorphic_paperclip generator, go ahead an run it as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;">script<span style="color:#006600; font-weight:bold;">/</span>generate polymorphic_paperclip</pre></div></div>

<p>Before you go and run rake db:migrate, open up the migration and modify the assets_count to attachings_count &#8211; it seems there is a minor bug.  I notified the author of the plugin and will submit a patch via git.  Now its OK to run rake db:migrate</p>
<p>Now we have the migration generated and the tables have been added to your database. Next we have to add (or change if you already have paperclip setup) the model where you want to have attachments by adding  acts_as_polymorphic_paperclip.  As an example, I posted my documents model below.</p>

<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Document <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#CC00FF; font-weight:bold;"><span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span></span>
<span style="color:#008000; font-style:italic;"># Document Belongs To A User</span>
<span style="color:#5A0A0A; font-weight:bold;">belongs_to</span> <span style="color:#ff3333; font-weight:bold;">:user</span>
<span style="color:#008000; font-style:italic;"># for paperclip (polymorphic)</span>
acts_as_polymorphic_paperclip 
<span style="color:#008000; font-style:italic;"># Validations</span>
...</pre></div></div>

<p><strong>Note: </strong> Ideally I would like to be able to override the styles settings that are set in the plugins assets.rb, however I went ahead and hard coded them there to fit my needs. Example:</p>

<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Asset <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#CC00FF; font-weight:bold;"><span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span></span>
  <span style="color:#5A0A0A; font-weight:bold;">has_many</span> <span style="color:#ff3333; font-weight:bold;">:attachings</span>, <span style="color:#ff3333; font-weight:bold;">:dependent</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> :<span style="color:#5A0A0A; font-weight:bold;">destroy</span>
  has_attached_file <span style="color:#ff3333; font-weight:bold;">:data</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;">:thumb</span><span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;100x100#&quot;</span>,
                    <span style="color:#ff3333; font-weight:bold;">:small</span>  <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;150x150&gt;&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&gt;&quot;</span>,
                    <span style="color:#ff3333; font-weight:bold;">:large</span> <span style="color:#006600; font-weight:bold;">=&gt;</span>   <span style="color:#996600;">&quot;500x500&gt;&quot;</span>,
                    <span style="color:#ff3333; font-weight:bold;">:xlarge</span> <span style="color:#006600; font-weight:bold;">=&gt;</span>   <span style="color:#996600;">&quot;600x600&gt;&quot;</span>,
                    <span style="color:#ff3333; font-weight:bold;">:xxlarge</span> <span style="color:#006600; font-weight:bold;">=&gt;</span>   <span style="color:#996600;">&quot;800x800&gt;&quot;</span> <span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

<p>For now, lets move onto the views where you are going to allow attachments.  We are just going to have one upload, perhaps in another tutorial we will look at handling multiple uploads.  </p>
<p>You need to make sure you put the html => { :multipart => true } in both your edit and new views for the model you are working with. Example in my case:</p>

<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#5A0A0A; font-weight:bold;">form_for</span><span style="color:#006600; font-weight:bold;">&#40;</span>@document,:html <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;">:multipart</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span> <span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  <span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">error_messages</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  <span style="color:#006600; font-weight:bold;">&lt;%</span>= <span style="color:#5A0A0A; font-weight:bold;">render</span> <span style="color:#ff3333; font-weight:bold;">:partial</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'form'</span>, <span style="color:#ff3333; font-weight:bold;">:locals</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;">:f</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> f <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></div></div>

<p>Next you need to add the file upload field to your _form or edit/new views.</p>

<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;">&lt;p&gt;
  Attach a file or image &lt;br /&gt;
  <span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#5A0A0A; font-weight:bold;">file_field</span> <span style="color:#ff3333; font-weight:bold;">:data</span><span style="color:#006600; font-weight:bold;">%&gt;</span>
&lt;/p&gt;</pre></div></div>

<p>Now lets go ahead and make these attachments viewable in the document.  For the edit view I added the following:</p>

<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;">&lt;p&gt;<span style="color:#006600; font-weight:bold;">&lt;%</span>= <span style="color:#5A0A0A; font-weight:bold;">image_tag</span> asset.<span style="color:#9900CC;">url</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:medium</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/p&gt;
&lt;p&gt;Tiny:  <span style="color:#006600; font-weight:bold;">&lt;%</span>= asset.<span style="color:#9900CC;">url</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:tiny</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;br /&gt;
 Small:  <span style="color:#006600; font-weight:bold;">&lt;%</span>= asset.<span style="color:#9900CC;">url</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:small</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;br /&gt;
 Medium:  <span style="color:#006600; font-weight:bold;">&lt;%</span>= asset.<span style="color:#9900CC;">url</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:medium</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;br /&gt;
 Large:  <span style="color:#006600; font-weight:bold;">&lt;%</span>= asset.<span style="color:#9900CC;">url</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:large</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;br /&gt;
 XL:  <span style="color:#006600; font-weight:bold;">&lt;%</span>= asset.<span style="color:#9900CC;">url</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:xlarge</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;br /&gt;
 XXL:  <span style="color:#006600; font-weight:bold;">&lt;%</span>= asset.<span style="color:#9900CC;">url</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:xxlarge</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;br /&gt;   
 Original:  <span style="color:#006600; font-weight:bold;">&lt;%</span>= asset.<span style="color:#9900CC;">url</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
&lt;/p&gt;</pre></div></div>

<p><em><strong>Other Notes:</strong></em></p>
<p>You can use this to attach an attachment if you were going to use a different view, for example an upload view with @document.assets.attach(@asset)</p>
<p>You can nuke an attachment by either calling @document.assets.detach or @document.assets.detach(@asset) depending upon how you are going about dealing with removing attachments. @document.assets.detach  will nuke ALL attachments associated with that document, @document.essay.assets.detach(@asset) will nuke just that asset you are referencing. </p>
]]></content:encoded>
			<wfw:commentRss>http://burm.net/2008/10/17/ruby-on-rails-polymorphic-paperclip-plugin-tutorial/feed/</wfw:commentRss>
		<slash:comments>45</slash:comments>
		</item>
		<item>
		<title>The Ruby On Rails Paperclip Plugin Tutorial &#8211; Easy Image Attachments</title>
		<link>http://burm.net/2008/10/07/the-ruby-on-rails-paperclip-plugin-tutorial-easy-image-attachments/</link>
		<comments>http://burm.net/2008/10/07/the-ruby-on-rails-paperclip-plugin-tutorial-easy-image-attachments/#comments</comments>
		<pubDate>Wed, 08 Oct 2008 01:00:38 +0000</pubDate>
		<dc:creator>John Burmeister</dc:creator>
				<category><![CDATA[My Projects]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[paperclip]]></category>
		<category><![CDATA[RoR]]></category>

		<guid isPermaLink="false">http://burm.net/?p=127</guid>
		<description><![CDATA[I used Paperclip for my latest project, and I figured I would give a brief tutorial on how to use it. Paperclip &#8211; Paperclip is intended as an easy file attachment library for ActiveRecord. The intent behind it was to keep setup as easy as possible and to treat files as much like other attributes [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fburm.net%2F2008%2F10%2F07%2Fthe-ruby-on-rails-paperclip-plugin-tutorial-easy-image-attachments%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fburm.net%2F2008%2F10%2F07%2Fthe-ruby-on-rails-paperclip-plugin-tutorial-easy-image-attachments%2F&amp;source=burmjohn&amp;style=compact&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I used Paperclip for my latest project, and I figured I would give a brief tutorial on how to use it.</p>
<p><strong>Paperclip</strong> &#8211; Paperclip is intended as an easy file attachment library for ActiveRecord. The intent behind it was to keep setup as easy as possible and to treat files as much like other attributes as possible. <a href="http://github.com/thoughtbot/paperclip/tree/master">http://github.com/thoughtbot/paperclip/tree/master</a></p>
<p>In my case, I wanted to allow an attachment to an Event, which will have one photo.</p>
<p>To install:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">script<span style="color:#006600; font-weight:bold;">/</span>plugin install git:<span style="color:#006600; font-weight:bold;">//</span>github.<span style="color:#9900CC;">com</span><span style="color:#006600; font-weight:bold;">/</span>thoughtbot<span style="color:#006600; font-weight:bold;">/</span>paperclip.<span style="color:#9900CC;">git</span></pre></div></div>

<p>Create your migration, again in my case I was adding the images to my Events model / DB, so I did the following:</p>

<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;">script<span style="color:#006600; font-weight:bold;">/</span>generate migration AddPhotosToEvents</pre></div></div>

<p>Open up your newly created migration with your favorite Text editor, and add the following:</p>

<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> AddPhotoToEvent <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#CC00FF; font-weight:bold;"><span style="color:#6666ff; font-weight:bold;">ActiveRecord::Migration</span></span>
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">up</span>
    add_column <span style="color:#ff3333; font-weight:bold;">:events</span>, <span style="color:#ff3333; font-weight:bold;">:photo_file_name</span>, <span style="color:#ff3333; font-weight:bold;">:string</span>
    add_column <span style="color:#ff3333; font-weight:bold;">:events</span>, <span style="color:#ff3333; font-weight:bold;">:photo_content_type</span>, <span style="color:#ff3333; font-weight:bold;">:string</span>
    add_column <span style="color:#ff3333; font-weight:bold;">:events</span>, <span style="color:#ff3333; font-weight:bold;">:photo_file_size</span>, <span style="color:#ff3333; font-weight:bold;">:integer</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">down</span>
    remove_column <span style="color:#ff3333; font-weight:bold;">:events</span>, <span style="color:#ff3333; font-weight:bold;">:photo_file_name</span>
    remove_column <span style="color:#ff3333; font-weight:bold;">:events</span>, <span style="color:#ff3333; font-weight:bold;">:photo_content_type</span>
    remove_column <span style="color:#ff3333; font-weight:bold;">:events</span>, <span style="color:#ff3333; font-weight:bold;">:photo_file_size</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Then rake your migration so the new columns are added to your database:</p>

<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;">rake db:migrate</pre></div></div>

<p>Next you need to tell your model to use Paperclip, again I am using the Event model as an example, the #Paperclip and below is what you need to add.  If you notice below I added 4 options to the :styles.  I wanted to have a few different sizes generated when a image was uploaded, i named them appropriately (you can name them whatever you wish).   Please note when you put a # on the end it signifies that you want that <strong>exact</strong> aspect ratio, it will crop your photo automatically.  When you use > on the end it will make the largest side the size you specify and keep the aspect ratio uploaded.  In addition note that because we specified has_attached_file :photo its going to look for that naming convention we created in the migration above.  In addition it uses that name to store your photo in the public folder of your application.  So our photo url is going to be as follows: /public/photos/(event#)/(size_name)/image_name</p>

<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Event <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#CC00FF; font-weight:bold;"><span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span></span>
<span style="color:#5A0A0A; font-weight:bold;">belongs_to</span> <span style="color:#ff3333; font-weight:bold;">:user</span>
<span style="color:#5A0A0A; font-weight:bold;">validates_presence_of</span> <span style="color:#ff3333; font-weight:bold;">:title</span>, <span style="color:#ff3333; font-weight:bold;">:on</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:create</span>, <span style="color:#ff3333; font-weight:bold;">:message</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;can't be blank&quot;</span>
<span style="color:#5A0A0A; font-weight:bold;">validates_presence_of</span> <span style="color:#ff3333; font-weight:bold;">:teaser</span>, <span style="color:#ff3333; font-weight:bold;">:on</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:create</span>, <span style="color:#ff3333; font-weight:bold;">:message</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;can't be blank&quot;</span>
<span style="color:#5A0A0A; font-weight:bold;">validates_presence_of</span> <span style="color:#ff3333; font-weight:bold;">:subject</span>, <span style="color:#ff3333; font-weight:bold;">:on</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:create</span>, <span style="color:#ff3333; font-weight:bold;">:message</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;can't be blank&quot;</span>
<span style="color:#008000; font-style:italic;"># Paperclip</span>
has_attached_file <span style="color:#ff3333; font-weight:bold;">:photo</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;">:thumb</span><span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;100x100#&quot;</span>,
    <span style="color:#ff3333; font-weight:bold;">:small</span>  <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;150x150&gt;&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&gt;&quot;</span>,
    <span style="color:#ff3333; font-weight:bold;">:large</span> <span style="color:#006600; font-weight:bold;">=&gt;</span>   <span style="color:#996600;">&quot;400x400&gt;&quot;</span> <span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

<p>Next you need to make sure you put the html => { :multipart => true } in <strong>both </strong>your edit and new views for the model you are working with.  Example in my case:</p>

<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#5A0A0A; font-weight:bold;">form_for</span><span style="color:#006600; font-weight:bold;">&#40;</span>@event,:html <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;">:multipart</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span> <span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  <span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">error_messages</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  <span style="color:#006600; font-weight:bold;">&lt;%</span>= <span style="color:#5A0A0A; font-weight:bold;">render</span> <span style="color:#ff3333; font-weight:bold;">:partial</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'form'</span>, <span style="color:#ff3333; font-weight:bold;">:locals</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;">:f</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> f <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></div></div>

<p>You then need to add the file_field to your new and edit forms or your _form partial like in my case:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;p&gt;
  &lt;%= f.label 'Photo' %&gt;&lt;br /&gt;
  &lt;%= f.file_field :photo %&gt;
&lt;/p&gt;</pre></div></div>

<p>Next up is deciding on how you are going to use / view your images.   In my case I wanted to show a few different sizes in the Event view.  I also wanted to make sure I am only going to show photo&#8217;s if one exists. In this example I am just showing the small and medium sizes we generated:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;% if @event.photo.exists? then %&gt;
&lt;p&gt;Small:&lt;%= image_tag @event.photo.url(:small) %&gt;&lt;/p&gt;
&lt;p&gt;Medium:&lt;%= image_tag @event.photo.url(:medium) %&gt;&lt;/p&gt;
&lt;% else %&gt;
&lt;p&gt; There are no photo's attached, upload one. &lt;/p&gt;
&lt;% end %&gt;</pre></div></div>

<h3>A few other notes&#8230;</h3>
<p>
Calling @event.photo.nil destroys the photo</p>
<p>Also checkout this great tutorial <a href="http://jimneath.org/2008/04/17/paperclip-attaching-files-in-rails/" target="_blank">Jim put up here.</a></p>
<p><a href="http://jimneath.org/2008/04/17/paperclip-attaching-files-in-rails/" target="_blank"></a><br />
Thats all for now, I&#8217;ll try to post an update with some more options / features when using the Paperclip plugin in the future.</p>
<p>*** Checkout my other tutorial on <a href="http://burm.net/2008/10/17/ruby-on-rails-polymorphic-paperclip-plugin-tutorial/">polymorphic paperclip</a> if you would like to have multiple image attachments.</p>
]]></content:encoded>
			<wfw:commentRss>http://burm.net/2008/10/07/the-ruby-on-rails-paperclip-plugin-tutorial-easy-image-attachments/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
	</channel>
</rss>

