<?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; Ruby on Rails</title>
	<atom:link href="http://burm.net/category/ruby-on-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://burm.net</link>
	<description>John Burmeister's Blog</description>
	<lastBuildDate>Thu, 06 May 2010 20:04:16 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<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 that [...]]]></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"><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" height="61" width="51" /></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>Quick Ruby On Rails Tip for Nested Resources</title>
		<link>http://burm.net/2008/11/01/quick-ruby-on-rails-quick-tip-for-nested-resources/</link>
		<comments>http://burm.net/2008/11/01/quick-ruby-on-rails-quick-tip-for-nested-resources/#comments</comments>
		<pubDate>Sun, 02 Nov 2008 00:33:59 +0000</pubDate>
		<dc:creator>John Burmeister</dc:creator>
				<category><![CDATA[My Projects]]></category>
		<category><![CDATA[Remodeling]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://burm.net/?p=178</guid>
		<description><![CDATA[Just a quick tip for when you are doing nested resources&#8230;.
In this example, I am building a app for a client where there is a recipient and they have many physicians.  So I have a case where I have a nested resource.  To keep thing DRY, I added this to my before filter [...]]]></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%2F11%2F01%2Fquick-ruby-on-rails-quick-tip-for-nested-resources%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fburm.net%2F2008%2F11%2F01%2Fquick-ruby-on-rails-quick-tip-for-nested-resources%2F" height="61" width="51" /></a></div><p>Just a quick tip for when you are doing nested resources&#8230;.</p>
<p>In this example, I am building a app for a client where there is a recipient and they have many physicians.  So I have a case where I have a nested resource.  To keep thing DRY, I added this to my before filter where I get the recipient. This allows you to nuke the find in the show, edit, update and delete actions and retain the original use of @physician.  </p>
<pre>
def get_recipient
  @recipient = Recipient.find(params[:recipient_id])
  # DRYs her up a little so you don't have a find in the show,edit,update and delete actions
  @physician = @recipient.physicians.find(params[:id]) if params[:id]
end
</pre>
<p>Don&#8217;t forget to modify your index find, change it to reflect the nested route&#8230; In my case:</p>
<pre>
    @physicians = @recipient.physicians.find(:all)
</pre>
<p>Have any other useful tips? Let me know!</p>
]]></content:encoded>
			<wfw:commentRss>http://burm.net/2008/11/01/quick-ruby-on-rails-quick-tip-for-nested-resources/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[Ruby on Rails]]></category>
		<category><![CDATA[programming]]></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 artist tracking site, shows [...]]]></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"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fburm.net%2F2008%2F10%2F19%2Frails-rumble-2008-app-list%2F" height="61" width="51" /></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, [...]]]></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"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fburm.net%2F2008%2F10%2F17%2Frails-rumble-2008-has-started%2F" height="61" width="51" /></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[Ruby on Rails]]></category>
		<category><![CDATA[programming]]></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. [...]]]></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"><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" height="61" width="51" /></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:#6666ff; font-weight:bold;">ActiveRecord::Base</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:#6666ff; font-weight:bold;">ActiveRecord::Base</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:#ff3333; 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>40</slash:comments>
		</item>
		<item>
		<title>Acts As Taggable on Steroids Ruby On Rails Plugin With Paginate</title>
		<link>http://burm.net/2008/10/08/acts-as-taggable-on-steroids-ruby-on-rails-plugin-with-paginate/</link>
		<comments>http://burm.net/2008/10/08/acts-as-taggable-on-steroids-ruby-on-rails-plugin-with-paginate/#comments</comments>
		<pubDate>Wed, 08 Oct 2008 05:48:33 +0000</pubDate>
		<dc:creator>John Burmeister</dc:creator>
				<category><![CDATA[My Projects]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Rails Plugins]]></category>
		<category><![CDATA[Rails Tutorials]]></category>

		<guid isPermaLink="false">http://burm.net/?p=133</guid>
		<description><![CDATA[Acts As Taggable On Steroids is a great plugin for Rails that makes adding tags to your application quick and easy.  Check it out on github here => http://github.com/mattetti/acts_as_taggable_on_steroids/tree/master
I threw this post together with some notes that I took along the way when setting up the plugin for use. 
Installation:

script/plugin install http://svn.viney.net.nz/things/rails/plugins/acts_as_taggable_on_steroids

Setup
Setup your migration [...]]]></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%2F08%2Facts-as-taggable-on-steroids-ruby-on-rails-plugin-with-paginate%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fburm.net%2F2008%2F10%2F08%2Facts-as-taggable-on-steroids-ruby-on-rails-plugin-with-paginate%2F" height="61" width="51" /></a></div><p>Acts As Taggable On Steroids is a great plugin for Rails that makes adding tags to your application quick and easy.  Check it out on github here => <a href="http://github.com/mattetti/acts_as_taggable_on_steroids/tree/master">http://github.com/mattetti/acts_as_taggable_on_steroids/tree/master</a></p>
<p>I threw this post together with some notes that I took along the way when setting up the plugin for use. </p>
<p><strong>Installation:</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 install http:<span style="color:#006600; font-weight:bold;">//</span>svn.<span style="color:#9900CC;">viney</span>.<span style="color:#9900CC;">net</span>.<span style="color:#9900CC;">nz</span><span style="color:#006600; font-weight:bold;">/</span>things<span style="color:#006600; font-weight:bold;">/</span>rails<span style="color:#006600; font-weight:bold;">/</span>plugins<span style="color:#006600; font-weight:bold;">/</span>acts_as_taggable_on_steroids</pre></div></div>

<p><strong>Setup</strong></p>
<p>Setup your migration by running the below:</p>
<pre lang ="rails">
ruby script/generate acts_as_taggable_migration
rake db:migrate
</pre>
<p>Add the acts_as_taggable to your model, in my case its the Events model&#8230;</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:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
<span style="color:#008000; font-style:italic;"># acts as taggable on roids</span>
acts_as_taggable</pre></div></div>

<p>Now I needed to add a way to allow tags to be added to Events, in my form for my Event I added the following:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;p&gt;
  &lt;%= f.label 'Tag List (Delimiter = ,)' %&gt;&lt;br /&gt;
  &lt;%= f.text_field :tag_list %&gt;
&lt;/p&gt;</pre></div></div>

<p>To view the tags associated this a Event on the Show page, along with linking to the actual tag to search for other events tagged with the same item, I added the following:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;p&gt;&lt;strong&gt;This event was tagged with&lt;/strong&gt;: &lt;% for tag in @event.tags %&gt; 
&lt;%= link_to tag.name, events_path(:view =&gt;'tag', :tag =&gt; tag.name) %&gt;&lt;% end %&gt;
&lt;/p&gt;</pre></div></div>

<p><strong>Tag Clouds </strong></p>
<p>In order to use the plugin&#8217;s build in tag cloud functionality you need to add the helper to your application helper by doing the following:</p>

<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;">  <span style="color:#9966CC; font-weight:bold;">module</span> ApplicationHelper
    <span style="color:#9966CC; font-weight:bold;">include</span> TagsHelper
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>In your controller where you are planning on using your tag cloud add the below, this will grab the counts of all your tags so the helper can generate your cloud. Again in my case I am putting this in my Events controller.</p>

<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;"><span style="color:#0066ff; font-weight:bold;">@tags</span> = Event.<span style="color:#9900CC;">tag_counts</span></pre></div></div>

<p>Now you use the following where you wish to show your views:</p>

<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span> tag_cloud <span style="color:#0066ff; font-weight:bold;">@tags</span>, <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#40;</span>tag1 tag2 tag3 tag4<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>tag, css_class<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>= <span style="color:#5A0A0A; font-weight:bold;">link_to</span> <span style="color:#5A0A0A; font-weight:bold;">tag</span>.<span style="color:#9900CC;">name</span>, <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:action</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:tag</span>, <span style="color:#ff3333; font-weight:bold;">:id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#5A0A0A; font-weight:bold;">tag</span>.<span style="color:#9900CC;">name</span> <span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#ff3333; font-weight:bold;">:class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> css_class <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>In your main CSS file you should add something to match the tags we specified above, this sets your font sizes for the cloud display generated by the helper&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">  <span style="color: #6666ff;">.tag1</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1.0em</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
  <span style="color: #6666ff;">.tag2</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1.6em</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
  <span style="color: #6666ff;">.tag3</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">2.7em</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
  <span style="color: #6666ff;">.tag4</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">3.8em</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p><strong>Tag Clouds with Paginate Example</strong></p>
<p>Here I am passing the page and tag to my events model to find all events tagged with that tag, and then use the results of that query and passing it onto paginate.</p>

<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">tag_event_list</span><span style="color:#006600; font-weight:bold;">&#40;</span>page, <span style="color:#5A0A0A; font-weight:bold;">tag</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
 options = Event.<span style="color:#9900CC;">find_options_for_find_tagged_with</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#5A0A0A; font-weight:bold;">tag</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">merge</span> <span style="color:#ff3333; font-weight:bold;">:page</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> page, <span style="color:#ff3333; font-weight:bold;">:per_page</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">10</span>, <span style="color:#ff3333; font-weight:bold;">:order</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'date DESC'</span> 
 <span style="color:#5A0A0A; font-weight:bold;">paginate</span><span style="color:#006600; font-weight:bold;">&#40;</span>options<span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Other Notes:</p>
<p>I added the following to my environment.rb file so that the unused tags get destroyed if they are no longer in use by any events.</p>

<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># automatically remove dead tags</span>
Tag.<span style="color:#9900CC;">destroy_unused</span> = <span style="color:#0000FF; font-weight:bold;">true</span></pre></div></div>

<p>For more help check out the read me here: <a href="http://github.com/mattetti/acts_as_taggable_on_steroids/tree/master">http://github.com/mattetti/acts_as_taggable_on_steroids/tree/maste</a>r</p>
]]></content:encoded>
			<wfw:commentRss>http://burm.net/2008/10/08/acts-as-taggable-on-steroids-ruby-on-rails-plugin-with-paginate/feed/</wfw:commentRss>
		<slash:comments>4</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[Ruby on Rails]]></category>
		<category><![CDATA[programming]]></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 as [...]]]></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"><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" height="61" width="51" /></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:#6666ff; font-weight:bold;">ActiveRecord::Migration</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:#6666ff; font-weight:bold;">ActiveRecord::Base</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>16</slash:comments>
		</item>
		<item>
		<title>A few great plugins that I am using in my current Ruby on Rails project</title>
		<link>http://burm.net/2008/10/06/a-few-great-plugins-that-i-am-using-in-my-current-ruby-on-rails-project/</link>
		<comments>http://burm.net/2008/10/06/a-few-great-plugins-that-i-am-using-in-my-current-ruby-on-rails-project/#comments</comments>
		<pubDate>Tue, 07 Oct 2008 03:12:21 +0000</pubDate>
		<dc:creator>John Burmeister</dc:creator>
				<category><![CDATA[My Projects]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Rails Plugins]]></category>
		<category><![CDATA[Rails Tutorials]]></category>

		<guid isPermaLink="false">http://burm.net/?p=113</guid>
		<description><![CDATA[I am currently working on an interesting project for a customer of mine.   Hopefully I&#8217;ll be able to share more of the details with you all when the project is near completion.  The project involves creating events, parsing and caching RSS feeds, generating RSS feeds, as well as Emailing and SMS&#8217;ing subscribers daily events.   I [...]]]></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%2F06%2Fa-few-great-plugins-that-i-am-using-in-my-current-ruby-on-rails-project%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fburm.net%2F2008%2F10%2F06%2Fa-few-great-plugins-that-i-am-using-in-my-current-ruby-on-rails-project%2F" height="61" width="51" /></a></div><p>I am currently working on an interesting project for a customer of mine.   Hopefully I&#8217;ll be able to share more of the details with you all when the project is near completion.  The project involves creating events, parsing and caching RSS feeds, generating RSS feeds, as well as Emailing and SMS&#8217;ing subscribers daily events.   I have been working on the project for the last 5 days, and I am about one third of the way through.</p>
<p>I wanted to share some great plugins for Ruby on Rails that I have come across, along with some tutorials. Check back for an updated post with more info.</p>
<h2>Plugins:</h2>
<p><strong>Restful Authentication </strong>- This widely-used plugin provides a foundation for securely managing user authentication &#8211; <a href="http://github.com/technoweenie/restful-authentication/tree/master">http://github.com/technoweenie/restful-authentication/tree/master</a></p>
<p><strong>acts_as_taggable_on_steroids</strong> &#8211; This plugin is based on acts_as_taggable by DHH but includes extrassuch as tests, smarter tag assignment, and tag cloud calculations.  &#8211; <a href="http://github.com/mattetti/acts_as_taggable_on_steroids/tree/master  ">http://github.com/mattetti/acts_as_taggable_on_steroids/tree/master</a></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><strong>Paperclip Polymorph</strong> &#8211; This plugin allows users of the Paperclip plugin to easily share attached files between multiple models. <a href="http://locusfoc.us/2008/6/29/paperclip-polymorph">http://locusfoc.us/2008/6/29/paperclip-polymorph</a></p>
<p><strong>acts_as_textiled </strong>- This simple plugin allows you to forget about constantly rendering Textile in your application. Instead, you can rest easy knowing the Textile fields you want to display as HTML will always be displayed as HTML (unless you tell your code otherwise). <a href="http://github.com/defunkt/acts_as_textiled/tree/master">http://github.com/defunkt/acts_as_textiled/tree/master</a></p>
<p><strong>Will_paginate</strong> &#8211; Pagination is just limiting the number of records displayed. Why should you let it get in your way while developing, then? This plugin makes magic happen. <a href="http://github.com/mislav/will_paginate/tree/master">http://github.com/mislav/will_paginate/tree/master</a></p>
<h2>Tutorials / Guides:</h2>
<p>If you are new to Ruby on Rails be sure to check out the guides that are being worked on right now here: <a href="http://guides.rails.info/index.html">http://guides.rails.info/index.html</a></p>
<p><strong>Railscasts</strong> &#8211; Free Ruby on Rails Screencasts &#8211; <a href="http://railscasts.com/">http://railscasts.com/</a></p>
<p><strong>Learning Rails</strong> &#8211; Audio (Podcasts) and Screencasts -<a href="http://www.buildingwebapps.com/podcasts"> http://www.buildingwebapps.com/podcasts</a></p>
<p>Jim created a great list of plugins he found useful when he was building a social network in Rails. Check it out here: <a href="http://jimneath.org/2008/04/25/building-a-social-network-site-in-rails/">http://jimneath.org/2008/04/25/building-a-social-network-site-in-rails/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://burm.net/2008/10/06/a-few-great-plugins-that-i-am-using-in-my-current-ruby-on-rails-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ActiveScaffold &#8211; A Ruby on Rails plugin for dynamic, AJAX CRUD interfaces</title>
		<link>http://burm.net/2007/05/26/activescaffold-a-ruby-on-rails-plugin-for-dynamic-ajax-crud-interfaces/</link>
		<comments>http://burm.net/2007/05/26/activescaffold-a-ruby-on-rails-plugin-for-dynamic-ajax-crud-interfaces/#comments</comments>
		<pubDate>Sat, 26 May 2007 13:03:02 +0000</pubDate>
		<dc:creator>John Burmeister</dc:creator>
				<category><![CDATA[Rails Ecommerce Project]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://burm.net/2007/05/26/activescaffold-a-ruby-on-rails-plugin-for-dynamic-ajax-crud-interfaces/</guid>
		<description><![CDATA[After playing with streamlined, I discovered ActiveScaffold. ActiveScaffold seems to be a bit more fine tuned and ready for production use then streamlined when it comes to restful development. This is just what I was looking for the speed up the dev of the backend admin area. While its not a final solution, it allows [...]]]></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%2F2007%2F05%2F26%2Factivescaffold-a-ruby-on-rails-plugin-for-dynamic-ajax-crud-interfaces%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fburm.net%2F2007%2F05%2F26%2Factivescaffold-a-ruby-on-rails-plugin-for-dynamic-ajax-crud-interfaces%2F" height="61" width="51" /></a></div><p>After playing with streamlined, I discovered <a href="http://activescaffold.com/">ActiveScaffold</a>. ActiveScaffold seems to be a bit more fine tuned and ready for production use then streamlined when it comes to restful development. This is just what I was looking for the speed up the dev of the backend admin area. While its not a final solution, it allows you to get things going fast and start coding the core of your app without the need to code all the minor crud features in the beginning.  Its worth a look at, try the demo here: <a href="http://demo.activescaffold.com/users">http://demo.activescaffold.com/users</a></p>
<p>ActiveScaffold also allows you to override anything you need, layouts, columns, associations, etc.<br />
It doesn&#8217;t get more simple and clean then that. </p>
<p>Main features:</p>
<p>    *  An AJAXified table interface for creating, updating, and deleting objects<br />
    * Automatic handling of ActiveRecord associations<br />
    * Sorting, Search and Pagination<br />
    * Graceful JavaScript degradation<br />
    * RESTful API support (XML/YAML/JSON) baked in<br />
    * Sexy CSS styling and theming support<br />
    * More extension points than you can shake a stick at<br />
    * Guaranteed to work on Firefox 1+, IE 6+ and Safari 2+<br />
    * Released under the MIT License, the same one as Rails itself, so you can use it freely in your commercial applications.</p>
]]></content:encoded>
			<wfw:commentRss>http://burm.net/2007/05/26/activescaffold-a-ruby-on-rails-plugin-for-dynamic-ajax-crud-interfaces/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Working with edge rails &#8211; creating a project from scratch using edge rails</title>
		<link>http://burm.net/2007/05/25/working-with-edge-rails-creating-a-project-from-scratch-using-edge-rails/</link>
		<comments>http://burm.net/2007/05/25/working-with-edge-rails-creating-a-project-from-scratch-using-edge-rails/#comments</comments>
		<pubDate>Sat, 26 May 2007 02:24:36 +0000</pubDate>
		<dc:creator>John Burmeister</dc:creator>
				<category><![CDATA[Rails Ecommerce Project]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://burm.net/2007/05/25/working-with-edge-rails-creating-a-project-from-scratch-using-edge-rails/</guid>
		<description><![CDATA[This has always been something I was thinking of, why caint I create my project initially with edge rails?
There are always minor changes in edge rails that can effect creating your project from using the stable version.   Using the way below eliminates that issue by creating your initial project with edge.
mkdir -p new_project/vendor
cd [...]]]></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%2F2007%2F05%2F25%2Fworking-with-edge-rails-creating-a-project-from-scratch-using-edge-rails%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fburm.net%2F2007%2F05%2F25%2Fworking-with-edge-rails-creating-a-project-from-scratch-using-edge-rails%2F" height="61" width="51" /></a></div><p>This has always been something I was thinking of, why caint I create my project initially with edge rails?</p>
<p>There are always minor changes in edge rails that can effect creating your project from using the stable version.   Using the way below eliminates that issue by creating your initial project with edge.</p>
<p>mkdir -p new_project/vendor<br />
cd new_project<br />
svn co http://svn.rubyonrails.org/rails/trunk vendor/rails<br />
ruby vendor/rails/railties/bin/rails .</p>
<p>Now you have yourself a fresh project base to start your new edge rails app.</p>
]]></content:encoded>
			<wfw:commentRss>http://burm.net/2007/05/25/working-with-edge-rails-creating-a-project-from-scratch-using-edge-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
