<?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>Web Development by Joe Sak &#187; Tutorials</title>
	<atom:link href="http://www.joesak.com/category/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.joesak.com</link>
	<description>Rails, HTML5, CSS3, jQuery - Thoughts, Advice &#38; Work</description>
	<lastBuildDate>Tue, 27 Jul 2010 14:10:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Online Photo Gallery, Payment &amp; Order Fulfillment: Ruby on Rails Tutorial</title>
		<link>http://www.joesak.com/2009/09/18/online-photo-gallery-payment-order-fulfillment-ruby-on-rails-tutorial/</link>
		<comments>http://www.joesak.com/2009/09/18/online-photo-gallery-payment-order-fulfillment-ruby-on-rails-tutorial/#comments</comments>
		<pubDate>Fri, 18 Sep 2009 16:51:04 +0000</pubDate>
		<dc:creator>Joe Sak</dc:creator>
				<category><![CDATA[Custom Development]]></category>
		<category><![CDATA[Improving Code]]></category>
		<category><![CDATA[Photography]]></category>
		<category><![CDATA[Portfolio]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Websites]]></category>
		<category><![CDATA[ecommerce]]></category>
		<category><![CDATA[photos]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.joesak.com/?p=255</guid>
		<description><![CDATA[This post is a follow-up to the post on my personal blog, titled &#8220;Ruby on Rails Photo Gallery &#38; Shopping Cart with RESTful Authentication&#8221; In that article, I merely showed off what I&#8217;d done with Ruby on Rails, but I didn&#8217;t show anyone how. Well, I&#8217;ve gotten some comments from people asking me to show [...]]]></description>
			<content:encoded><![CDATA[<p>This post is a follow-up to the post on <a title="Joe Sak's Web Development Blog" href="http://www.joesak.com">my personal blog</a>, titled &#8220;<a title="Ruby on Rails Photo Gallery &amp; Shopping Cart with RESTful Authentication" href="http://www.joesak.com/2009/05/31/ruby-on-rails-photo-gallery-shopping-cart-restful-authentication/">Ruby on Rails Photo Gallery &amp; Shopping Cart with RESTful Authentication</a>&#8221; In that article, I merely showed off what I&#8217;d done with Ruby on Rails, but I didn&#8217;t show anyone how. Well, I&#8217;ve gotten some comments from people asking me to show them how to build it.</p>
<p>That&#8217;s what this post is for.</p>
<p>So on to the nitty gritty details.</p>
<p>Start with the RESTful Authentication Tutorial:</p>
<p><script src="http://gist.github.com/189148.js"></script> <a></a> Follow the README to install, but <a title="Fix #1 to RESTful Authentication Install" href="http://railsforum.com/viewtopic.php?pid=96632#p96632">READ THIS FIRST</a> to fix the ExceptionLogger error  Then <a href="http://railsforum.com/viewtopic.php?pid=99223#p99223">follow these instructions</a> to fix the OpenID plugin error  Make sure you get your <a href="http://recaptcha.net/whyrecaptcha.html">recaptcha keys</a> for the config.yml, otherwise failed login attempts will bust your application.  Fill out the config &amp; database.yml files accordingly, run your database create &amp; migrate rakes, fire up the server and make sure it looks good. Cool? Let&#8217;s move on:  <strong>Define the objects</strong> Let&#8217;s begin by pointing out what, exactly, we&#8217;ll be building this application around: <strong>Galleries </strong>of <strong>Photos </strong>that <strong>Customers</strong> can order with a private <strong>Account</strong> provided to them by an <strong>Admin</strong> who can manage the galleries and review the <strong>Orders</strong>, which are also available to their respective customers.  I will go through how to set up the following models like so:</p>
<ul>
<li>Galleries
<ul>
<li>has_many :photos</li>
<li>belongs_to :customer</li>
<li>title</li>
<li>acts_as_urlnameable (pretty URLs)</li>
</ul>
</li>
<li>Photos
<ul>
<li>belongs_to :gallery</li>
<li>paperclip attachment: image</li>
</ul>
</li>
<li>Customers
<ul>
<li>username, password, full name</li>
</ul>
</li>
<li>Orders
<ul>
<li>has_many :line_items</li>
<li>belongs_to :customer</li>
</ul>
</li>
<li>Line Items
<ul>
<li>belongs_to <img src='http://www.joesak.com/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> rder</li>
<li>quantity, size, price</li>
</ul>
</li>
</ul>
<p>So let&#8217;s build the Galleries first:  <script src="http://gist.github.com/189161.js"></script></p>
<p>Then edit the Gallery model:</p>
<p><script src="http://gist.github.com/189149.js"></script> That&#8217;ll be fine for now. Let&#8217;s add the Photos model with paperclip image attached:  <script src="http://gist.github.com/189151.js"></script></p>
<p>Now edit the Photo model as such:</p>
<p><script src="http://gist.github.com/189152.js"></script> You should read all about <a href="http://thoughtbot.com/projects/paperclip">the paperclip gem</a> if you need more info on this model. Basically, we&#8217;re telling it to allow image attachments to the Photo model.  Customers can be the RESTful Authentication Tutorial User model, just need to add a couple things here:  <script src="http://gist.github.com/189153.js"></script></p>
<p>Let&#8217;s worry about Orders and Line Items later. We&#8217;ll have to add a cart, too. I&#8217;ll cover it, but it is all derived from <a href="http://www.pragprog.com/titles/rails3/agile-web-development-with-rails">Agile Web Development with Ruby on Rails Third Edition</a></p>
<p>Run your rake db:migrate and confirm all is well. Delete the Galleries layout file so it uses the application layout.</p>
<p>Let&#8217;s go see http://localhost:3000/galleries and play around. Add a gallery and then go to edit it. This is where we&#8217;ll add SWFUpload. <a href="http://jimneath.org/2008/05/15/swfupload-paperclip-and-ruby-on-rails/">Follow Jim Neath&#8217;s advice for this</a>.</p>
<p>You&#8217;ll want a photos controller:</p>
<p><script src="http://gist.github.com/189155.js"></script> The create method I use is:  <script src="http://gist.github.com/189156.js"></script></p>
<p>I had no luck getting Jim Neath&#8217;s session fix working, so I put skip_before_filter :verify_authenticity_token in the Photos Controller. Bad? Yea, probably. I haven&#8217;t found a better way yet.</p>
<p>Add this code to app/views/galleries/edit.html.erb:</p>
<p><script src="http://gist.github.com/189157.js"></script> Which leads you to add the following partial: app/views/photos/_image.html.erb  <script src="http://gist.github.com/189159.js"></script></p>
<p>We&#8217;ll worry about the destroy link later, let&#8217;s integrate swfupload. <a href="http://code.google.com/p/swfupload/">Download the latest copy of SWFUpload</a>. Copy flash/swfupload.swf to public/flash (make directory first). Copy swfupload.js &amp; upload.js (in Jim Neath&#8217;s demo app) to public/javascripts. Copy Jim Neath&#8217;s swfupload.css file to public/stylesheets. Copy Jim Neath&#8217;s images/icons folder to public/images.</p>
<p>Add this code to app/views/galleries/edit.html.erb:</p>
<p><script src="http://gist.github.com/189160.js"></script></p>
<p>Yep, a lot is going on there. Reload your galleries/edit page and see if it&#8217;s still working <img src='http://www.joesak.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Ok, so this gets you to a functioning online photo gallery. Up next will be adding user accounts, a shopping cart, ordering options, customers &amp; paypal integration. Stay tuned!</p>
<p>For now, please find the <a href="http://github.com/joemsak/proofs_package">source</a> here: <a href="http://github.com/joemsak/proofs_package">http://github.com/joemsak/proofs_package</a></p>
<p>And for help on your project, visit us at <a href="http://www.simplifyadvance.com">http://www.simplifyadvance.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.joesak.com/2009/09/18/online-photo-gallery-payment-order-fulfillment-ruby-on-rails-tutorial/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced)
Database Caching 10/16 queries in 0.011 seconds using disk

Served from: www.joesak.com @ 2010-09-08 01:52:02 -->