<?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>skater coder &#187; Coding Tips</title>
	<atom:link href="http://www.skatercoder.com/category/coding-tips/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.skatercoder.com</link>
	<description>angela chng - Ruby on Rails / PHP web developer &#38; skater girl in Singapore</description>
	<lastBuildDate>Wed, 18 May 2011 06:35:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Testing Spree with cucumber + spork + autotest + pickle + factory girl</title>
		<link>http://www.skatercoder.com/2010/09/04/testing-spree-with-cucumber-spork-autotest-pickle/</link>
		<comments>http://www.skatercoder.com/2010/09/04/testing-spree-with-cucumber-spork-autotest-pickle/#comments</comments>
		<pubDate>Sat, 04 Sep 2010 13:10:22 +0000</pubDate>
		<dc:creator>roadburn</dc:creator>
				<category><![CDATA[Coding Tips]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[autotest]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[factory girl]]></category>
		<category><![CDATA[pickle]]></category>
		<category><![CDATA[spork]]></category>

		<guid isPermaLink="false">http://www.skatercoder.com/?p=439</guid>
		<description><![CDATA[Copy this from the spree root folder into your app 1 2 3 spree-0.11.0/features to yourapp/features Edit features/support/env.rb 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 [...]]]></description>
			<content:encoded><![CDATA[<p>Copy this from the spree root folder into your app</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">spree-0.11.0<span style="color: #000000; font-weight: bold;">/</span>features
to 
yourapp<span style="color: #000000; font-weight: bold;">/</span>features</pre></td></tr></table></div>

<p>Edit features/support/env.rb</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;RAILS_ENV&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">||</span>= <span style="color:#996600;">&quot;cucumber&quot;</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'spork'</span>
&nbsp;
Spork.<span style="color:#9900CC;">prefork</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">expand_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">dirname</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">'/../../config/environment'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
  <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'cucumber/formatter/unicode'</span> <span style="color:#008000; font-style:italic;"># Remove this line if you don't want Cucumber Unicode support</span>
  <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'cucumber/rails/world'</span>
  <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'cucumber/rails/active_record'</span>
  <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'cucumber/web/tableish'</span>
&nbsp;
&nbsp;
  <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'capybara/rails'</span>
  <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'capybara/cucumber'</span>
  <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'capybara/session'</span>
  <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'cucumber/rails/capybara_javascript_emulation'</span> <span style="color:#008000; font-style:italic;"># Lets you click links with onclick javascript handlers without using @culerity or @javascript</span>
  <span style="color:#008000; font-style:italic;"># Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In</span>
  <span style="color:#008000; font-style:italic;"># order to ease the transition to Capybara we set the default here. If you'd</span>
  <span style="color:#008000; font-style:italic;"># prefer to use XPath just remove this line and adjust any selectors in your</span>
  <span style="color:#008000; font-style:italic;"># steps to use the XPath syntax.</span>
  Capybara.<span style="color:#9900CC;">default_selector</span> = <span style="color:#ff3333; font-weight:bold;">:css</span>
&nbsp;
&nbsp;
  <span style="color:#CC00FF; font-weight:bold;">Dir</span>.<span style="color:#9900CC;">glob</span><span style="color:#006600; font-weight:bold;">&#40;</span>SPREE_ROOT <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">'/db/default/*.{yml,csv,rb}'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>file<span style="color:#006600; font-weight:bold;">|</span>
    Fixtures.<span style="color:#9900CC;">create_fixtures</span><span style="color:#006600; font-weight:bold;">&#40;</span>SPREE_ROOT <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">'/db/default'</span>, <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">basename</span><span style="color:#006600; font-weight:bold;">&#40;</span>file, <span style="color:#996600;">'.*'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#CC00FF; font-weight:bold;">Dir</span>.<span style="color:#9900CC;">glob</span><span style="color:#006600; font-weight:bold;">&#40;</span>SPREE_ROOT <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">'/test/fixtures/*.{yml,csv,rb}'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>file<span style="color:#006600; font-weight:bold;">|</span>
    Fixtures.<span style="color:#9900CC;">create_fixtures</span><span style="color:#006600; font-weight:bold;">&#40;</span>SPREE_ROOT <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">'/test/fixtures'</span>, <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">basename</span><span style="color:#006600; font-weight:bold;">&#40;</span>file, <span style="color:#996600;">'.*'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'faker'</span>
  <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'factory_girl'</span>
&nbsp;
  <span style="color:#006600; font-weight:bold;">&#91;</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span>SPREE_ROOT, <span style="color:#996600;">'test'</span>, <span style="color:#996600;">'factories'</span>, <span style="color:#996600;">'*.rb'</span><span style="color:#006600; font-weight:bold;">&#41;</span>,
    <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span>RAILS_ROOT, <span style="color:#996600;">'vendor'</span>, <span style="color:#996600;">'extensions'</span>, <span style="color:#996600;">'*'</span>,
      <span style="color:#996600;">'{test,spec}'</span>, <span style="color:#996600;">'factories'</span>, <span style="color:#996600;">'*.rb'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>path<span style="color:#006600; font-weight:bold;">|</span>
    <span style="color:#CC00FF; font-weight:bold;">Dir</span>.<span style="color:#9900CC;">glob</span><span style="color:#006600; font-weight:bold;">&#40;</span>path<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>factory<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#CC0066; font-weight:bold;">require</span> factory <span style="color:#006600; font-weight:bold;">&#125;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'factory_girl/step_definitions'</span>
&nbsp;
  Zone.<span style="color:#9900CC;">class_eval</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">global</span>
      find_by_name<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;GlobalZone&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">||</span> Factory<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:global_zone</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  Product.<span style="color:#9900CC;">class_eval</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> taxon=<span style="color:#006600; font-weight:bold;">&#40;</span>taxon_name<span style="color:#006600; font-weight:bold;">&#41;</span>
      taxonomy = Taxonomy.<span style="color:#9900CC;">find_or_create_by_name</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Category&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      taxon = Taxon.<span style="color:#9900CC;">find_or_create_by_name_and_taxonomy_id</span><span style="color:#006600; font-weight:bold;">&#40;</span>taxon_name, taxonomy<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">taxons</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> taxon
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  ShippingMethod.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;UPS Ground&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:zone</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> Zone.<span style="color:#9900CC;">global</span>, <span style="color:#ff3333; font-weight:bold;">:calculator</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#6666ff; font-weight:bold;">Calculator::FlatRate</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
  coupon = Coupon.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:code</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;SPREE&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:description</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;$5 off any order&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:combine</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>, <span style="color:#ff3333; font-weight:bold;">:calculator</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#6666ff; font-weight:bold;">Calculator::FlatRate</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  coupon.<span style="color:#9900CC;">calculator</span>.<span style="color:#9900CC;">update_attribute</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:preferred_amount</span>, <span style="color:#006666;">5</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
Spork.<span style="color:#9900CC;">each_run</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#008000; font-style:italic;"># If you set this to false, any error raised from within your app will bubble</span>
  <span style="color:#008000; font-style:italic;"># up to your step definition and out to cucumber unless you catch it somewhere</span>
  <span style="color:#008000; font-style:italic;"># on the way. You can make Rails rescue errors and render error pages on a</span>
  <span style="color:#008000; font-style:italic;"># per-scenario basis by tagging a scenario or feature with the @allow-rescue tag.</span>
  <span style="color:#008000; font-style:italic;">#</span>
  <span style="color:#008000; font-style:italic;"># If you set this to true, Rails will rescue all errors and render error</span>
  <span style="color:#008000; font-style:italic;"># pages, more or less in the same way your application would behave in the</span>
  <span style="color:#008000; font-style:italic;"># default production environment. It's not recommended to do this for all</span>
  <span style="color:#008000; font-style:italic;"># of your scenarios, as this makes it hard to discover errors in your application.</span>
  <span style="color:#6666ff; font-weight:bold;">ActionController::Base</span>.<span style="color:#9900CC;">allow_rescue</span> = <span style="color:#0000FF; font-weight:bold;">false</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># If you set this to true, each scenario will run in a database transaction.</span>
  <span style="color:#008000; font-style:italic;"># You can still turn off transactions on a per-scenario basis, simply tagging</span>
  <span style="color:#008000; font-style:italic;"># a feature or scenario with the @no-txn tag. If you are using Capybara,</span>
  <span style="color:#008000; font-style:italic;"># tagging with @culerity or @javascript will also turn transactions off.</span>
  <span style="color:#008000; font-style:italic;">#</span>
  <span style="color:#008000; font-style:italic;"># If you set this to false, transactions will be off for all scenarios,</span>
  <span style="color:#008000; font-style:italic;"># regardless of whether you use @no-txn or not.</span>
  <span style="color:#008000; font-style:italic;">#</span>
  <span style="color:#008000; font-style:italic;"># Beware that turning transactions off will leave data in your database</span>
  <span style="color:#008000; font-style:italic;"># after each scenario, which can lead to hard-to-debug failures in</span>
  <span style="color:#008000; font-style:italic;"># subsequent scenarios. If you do this, we recommend you create a Before</span>
  <span style="color:#008000; font-style:italic;"># block that will explicitly put your database in a known state.</span>
  <span style="color:#6666ff; font-weight:bold;">Cucumber::Rails::World</span>.<span style="color:#9900CC;">use_transactional_fixtures</span> = <span style="color:#0000FF; font-weight:bold;">true</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># How to clean your database when transactions are turned off. See</span>
  <span style="color:#008000; font-style:italic;"># http://github.com/bmabey/database_cleaner for more info.</span>
  <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'database_cleaner'</span>
  DatabaseCleaner.<span style="color:#9900CC;">strategy</span> = <span style="color:#ff3333; font-weight:bold;">:truncation</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>config/cucumber.yml</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span>
rerun = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">file</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'rerun.txt'</span><span style="color:#006600; font-weight:bold;">&#41;</span> ? <span style="color:#CC00FF; font-weight:bold;">IO</span>.<span style="color:#9900CC;">read</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'rerun.txt'</span><span style="color:#006600; font-weight:bold;">&#41;</span> : <span style="color:#996600;">&quot;&quot;</span>
rerun_opts = rerun.<span style="color:#9900CC;">to_s</span>.<span style="color:#9900CC;">strip</span>.<span style="color:#9900CC;">empty</span>? ? <span style="color:#996600;">&quot;--format progress features&quot;</span> : <span style="color:#996600;">&quot;--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}&quot;</span>
std_opts = <span style="color:#996600;">&quot;#{rerun_opts} --format rerun --out rerun.txt --strict --tags ~@wip&quot;</span>
<span style="color:#006600; font-weight:bold;">%&gt;</span>
default: --drb <span style="color:#006600; font-weight:bold;">&lt;%</span>= std_opts <span style="color:#006600; font-weight:bold;">%&gt;</span>
wip: --drb --tags @wip:3 --wip features
autotest: --drb features --guess --format 'pretty' --color
autotest-all: --drb features --guess --format 'progress' --color</pre></td></tr></table></div>

<p>config/environments/cucumber.rb</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'AUTOFEATURE'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;true&quot;</span>
ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'RSPEC'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;true&quot;</span></pre></td></tr></table></div>

<p>config/database.yml</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">cucumber:
  <span style="color:#006600; font-weight:bold;">&lt;&lt;</span>: <span style="color:#006600; font-weight:bold;">*</span>test</pre></td></tr></table></div>

<p>Run your tests!</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">$ spork cuc
$ autotest</pre></td></tr></table></div>

<h2>Resources</h2>
<p><a href="http://groups.google.com/group/spree-user/browse_thread/thread/81b006af48d3166d">http://groups.google.com/group/spree-user/browse_thread/thread/81b006af48d3166d</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.skatercoder.com/2010/09/04/testing-spree-with-cucumber-spork-autotest-pickle/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Commonly used Rails 2.3 commands</title>
		<link>http://www.skatercoder.com/2010/08/31/commonly-used-rails-2-3-command-line/</link>
		<comments>http://www.skatercoder.com/2010/08/31/commonly-used-rails-2-3-command-line/#comments</comments>
		<pubDate>Tue, 31 Aug 2010 05:43:58 +0000</pubDate>
		<dc:creator>roadburn</dc:creator>
				<category><![CDATA[Coding Tips]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[rails 2.3.5]]></category>

		<guid isPermaLink="false">http://www.skatercoder.com/?p=419</guid>
		<description><![CDATA[Rails 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 Setup rails app with mysql $ rails appname -d mysql &#160; Start server with debugging enabled $ script/server --debugger &#160; Start server with debugging enabled [...]]]></description>
			<content:encoded><![CDATA[<h2>Rails</h2>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">Setup rails app with mysql
$ rails appname <span style="color: #660033;">-d</span> mysql
&nbsp;
Start server with debugging enabled
$ script<span style="color: #000000; font-weight: bold;">/</span>server <span style="color: #660033;">--debugger</span>
&nbsp;
Start server with debugging enabled - specify environment
$ script<span style="color: #000000; font-weight: bold;">/</span>server <span style="color: #660033;">--debugger</span> <span style="color: #007800;">RAILS_ENV</span>=production
&nbsp;
Install required gems
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> rake gems:<span style="color: #c20cb9; font-weight: bold;">install</span>
&nbsp;
Run gem server <span style="color: #000000; font-weight: bold;">for</span> rdocs
$ gem server
&nbsp;
View routes 
$ rake routes
&nbsp;
Update Rails
$ rake rails:update
&nbsp;
Enter the console with specified environment
$ script<span style="color: #000000; font-weight: bold;">/</span>console
$ script<span style="color: #000000; font-weight: bold;">/</span>console development
$ script<span style="color: #000000; font-weight: bold;">/</span>console <span style="color: #7a0874; font-weight: bold;">test</span>
$ script<span style="color: #000000; font-weight: bold;">/</span>console production
&nbsp;
Clear logfiles
$ rake log:<span style="color: #c20cb9; font-weight: bold;">clear</span></pre></td></tr></table></div>

<h2>Database</h2>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">Create database
$ rake db:create
&nbsp;
Run database migrations
$ rake db:migrate
&nbsp;
Drop database
$ rake db:drop
&nbsp;
Rollback database migration
$ rake db:rollback</pre></td></tr></table></div>

<h2>Testing</h2>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">Clone database <span style="color: #000000; font-weight: bold;">for</span> testing
$ rake db:<span style="color: #7a0874; font-weight: bold;">test</span>:clone
&nbsp;
Bootstrap Rspec
$ script<span style="color: #000000; font-weight: bold;">/</span>generate rspec
&nbsp;
Bootstrap Cucumber
$ script<span style="color: #000000; font-weight: bold;">/</span>generate cucumber <span style="color: #660033;">--rspec</span> <span style="color: #660033;">--capybara</span> <span style="color: #660033;">--spork</span>
&nbsp;
Bootstrap Pickle
$ script<span style="color: #000000; font-weight: bold;">/</span>generate pickle
&nbsp;
Generate Rspec model
$ script<span style="color: #000000; font-weight: bold;">/</span>generate rspec_model singularmodelname
&nbsp;
Generate Rspec controller
$ script<span style="color: #000000; font-weight: bold;">/</span>generate rspec_controller pluralmodelname
&nbsp;
Start spork <span style="color: #000000; font-weight: bold;">for</span> cucumber
$ spork cuc
&nbsp;
Run autotest
$ autotest</pre></td></tr></table></div>

<h2>Gems</h2>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">Install gems
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> gemname
&nbsp;
Uninstall gems
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> gem uninstall gemname
&nbsp;
Reinstall gems
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> gem pristine <span style="color: #660033;">--all</span>
&nbsp;
Remove old gems
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> gem clean</pre></td></tr></table></div>

<h2>Generators</h2>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">Generate migration
$ script<span style="color: #000000; font-weight: bold;">/</span>generate migration the_migration_name</pre></td></tr></table></div>

<h2>Heroku</h2>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">Push to Git
$ <span style="color: #c20cb9; font-weight: bold;">git</span> push heroku</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.skatercoder.com/2010/08/31/commonly-used-rails-2-3-command-line/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to upload multiple files on rails (uploadify + paperclip + jquery)</title>
		<link>http://www.skatercoder.com/2010/08/31/how-to-upload-multiple-files-on-rails-uploadify-paperclip-jquery/</link>
		<comments>http://www.skatercoder.com/2010/08/31/how-to-upload-multiple-files-on-rails-uploadify-paperclip-jquery/#comments</comments>
		<pubDate>Tue, 31 Aug 2010 04:27:50 +0000</pubDate>
		<dc:creator>roadburn</dc:creator>
				<category><![CDATA[Coding Tips]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[multiple files upload]]></category>
		<category><![CDATA[paperclip]]></category>
		<category><![CDATA[uploadify]]></category>

		<guid isPermaLink="false">http://www.skatercoder.com/?p=397</guid>
		<description><![CDATA[Setting Up Download Uploadify from http://www.uploadify.com/ copy the uploadify files into the following directories 1 2 3 4 5 6 7 public/javascripts/uploadify/jquery.uploadify-2.1.0.min.js public/javascripts/uploadify/uploadify.swf public/javascripts/uploadify/swfobject.js &#160; public/images/cancel.png &#160; public/stylesheets/uploadify.css Create this file app/middleware/flash_session_cookie_middleware.rb 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 require 'rack/utils' class FlashSessionCookieMiddleware def initialize&#40;app, session_key = [...]]]></description>
			<content:encoded><![CDATA[<h2>Setting Up</h2>
<p>Download Uploadify from<br />
<a href="http://www.uploadify.com/">http://www.uploadify.com/</a></p>
<p>copy the uploadify files into the following directories</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">public<span style="color: #000000; font-weight: bold;">/</span>javascripts<span style="color: #000000; font-weight: bold;">/</span>uploadify<span style="color: #000000; font-weight: bold;">/</span>jquery.uploadify-2.1.0.min.js
public<span style="color: #000000; font-weight: bold;">/</span>javascripts<span style="color: #000000; font-weight: bold;">/</span>uploadify<span style="color: #000000; font-weight: bold;">/</span>uploadify.swf
public<span style="color: #000000; font-weight: bold;">/</span>javascripts<span style="color: #000000; font-weight: bold;">/</span>uploadify<span style="color: #000000; font-weight: bold;">/</span>swfobject.js
&nbsp;
public<span style="color: #000000; font-weight: bold;">/</span>images<span style="color: #000000; font-weight: bold;">/</span>cancel.png
&nbsp;
public<span style="color: #000000; font-weight: bold;">/</span>stylesheets<span style="color: #000000; font-weight: bold;">/</span>uploadify.css</pre></td></tr></table></div>

<p>Create this file<br />
<strong>app/middleware/flash_session_cookie_middleware.rb</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rack/utils'</span> 
<span style="color:#9966CC; font-weight:bold;">class</span> FlashSessionCookieMiddleware 
  <span style="color:#9966CC; font-weight:bold;">def</span> initialize<span style="color:#006600; font-weight:bold;">&#40;</span>app, session_key = <span style="color:#996600;">'_session_id'</span><span style="color:#006600; font-weight:bold;">&#41;</span> 
    <span style="color:#0066ff; font-weight:bold;">@app</span> = app 
    <span style="color:#0066ff; font-weight:bold;">@session_key</span> = session_key 
  <span style="color:#9966CC; font-weight:bold;">end</span> 
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> call<span style="color:#006600; font-weight:bold;">&#40;</span>env<span style="color:#006600; font-weight:bold;">&#41;</span> 
    <span style="color:#9966CC; font-weight:bold;">if</span> env<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'HTTP_USER_AGENT'</span><span style="color:#006600; font-weight:bold;">&#93;</span> =~ <span style="color:#006600; font-weight:bold;">/</span>^<span style="color:#006600; font-weight:bold;">&#40;</span>Adobe<span style="color:#006600; font-weight:bold;">|</span>Shockwave<span style="color:#006600; font-weight:bold;">&#41;</span> Flash<span style="color:#006600; font-weight:bold;">/</span> 
      req = <span style="color:#6666ff; font-weight:bold;">Rack::Request</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>env<span style="color:#006600; font-weight:bold;">&#41;</span> 
      env<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'HTTP_COOKIE'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;#{@session_key}=#{req.params[@session_key]}&quot;</span>.<span style="color:#9900CC;">freeze</span> <span style="color:#9966CC; font-weight:bold;">unless</span> req.<span style="color:#9900CC;">params</span><span style="color:#006600; font-weight:bold;">&#91;</span>@session_key<span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#0000FF; font-weight:bold;">nil</span>? 
    <span style="color:#9966CC; font-weight:bold;">end</span> 
    <span style="color:#0066ff; font-weight:bold;">@app</span>.<span style="color:#9900CC;">call</span><span style="color:#006600; font-weight:bold;">&#40;</span>env<span style="color:#006600; font-weight:bold;">&#41;</span> 
  <span style="color:#9966CC; font-weight:bold;">end</span> 
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Add this line to<br />
<strong>config/initializers/session_store.rb</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#6666ff; font-weight:bold;">ActionController::Dispatcher</span>.<span style="color:#9900CC;">middleware</span>.<span style="color:#9900CC;">insert_before</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#6666ff; font-weight:bold;">ActionController::Base</span>.<span style="color:#9900CC;">session_store</span>, FlashSessionCookieMiddleware, <span style="color:#6666ff; font-weight:bold;">ActionController::Base</span>.<span style="color:#9900CC;">session_options</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:key</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></td></tr></table></div>

<p>Make sure your environment.rb file has this</p>
<p><strong>config/environment.rb</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#6666ff; font-weight:bold;">Rails::Initializer</span>.<span style="color:#9900CC;">run</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>config<span style="color:#006600; font-weight:bold;">|</span>
&nbsp;
  config.<span style="color:#9900CC;">gem</span> <span style="color:#996600;">'mime-types'</span>, <span style="color:#ff3333; font-weight:bold;">:lib</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'mime/types'</span>
  config.<span style="color:#9900CC;">gem</span> <span style="color:#996600;">'paperclip'</span> 
&nbsp;
  <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#40;</span>middleware<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>dir<span style="color:#006600; font-weight:bold;">|</span> 
    config.<span style="color:#9900CC;">load_paths</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#996600;">&quot;#{RAILS_ROOT}/app/#{dir}&quot;</span> 
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<h2>Models</h2>
<p>Let&#8217;s assume you want to create a photo album with many photos.</p>
<p>Create your photo model with the following:</p>
<p><strong>db/migrate/create_photos.rb</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> CreatePhotos <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>
    create_table <span style="color:#ff3333; font-weight:bold;">:photos</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>t<span style="color:#006600; font-weight:bold;">|</span>
      t.<span style="color:#CC0066; font-weight:bold;">integer</span> <span style="color:#ff3333; font-weight:bold;">:attachable_id</span>
      t.<span style="color:#CC0066; font-weight:bold;">string</span> <span style="color:#ff3333; font-weight:bold;">:description</span>  
      t.<span style="color:#CC0066; font-weight:bold;">string</span> <span style="color:#ff3333; font-weight:bold;">:data_file_name</span>  
      t.<span style="color:#CC0066; font-weight:bold;">string</span> <span style="color:#ff3333; font-weight:bold;">:data_content_type</span>  
      t.<span style="color:#CC0066; font-weight:bold;">integer</span> <span style="color:#ff3333; font-weight:bold;">:data_file_size</span>  
      t.<span style="color:#9900CC;">datetime</span> <span style="color:#ff3333; font-weight:bold;">:data_updated_at</span>
      t.<span style="color:#CC0066; font-weight:bold;">string</span> <span style="color:#ff3333; font-weight:bold;">:parent</span>  
    <span style="color:#9966CC; font-weight:bold;">end</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>
    drop_table <span style="color:#ff3333; font-weight:bold;">:images</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>In your album model:</p>
<p><strong>app/model/album.rb</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">has_many <span style="color:#ff3333; font-weight:bold;">:photos</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>, <span style="color:#ff3333; font-weight:bold;">:foreign_key</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:attachable_id</span></pre></td></tr></table></div>

<p>In your photo model:<br />
<strong>app/model/photo.rb</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">belongs_to <span style="color:#ff3333; font-weight:bold;">:album</span>, <span style="color:#ff3333; font-weight:bold;">:foreign_key</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:attachable_id</span>
&nbsp;
has_attached_file <span style="color:#ff3333; font-weight:bold;">:data</span>, 
      <span style="color:#ff3333; font-weight:bold;">:url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;/assets/images/:id/:style/:basename.:extension&quot;</span>,
      <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;:rails_root/public/assets/images/:id/:style/:basename.:extension&quot;</span>,
      <span style="color:#ff3333; font-weight:bold;">:styles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> 
      <span style="color:#ff3333; font-weight:bold;">:large</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;800x800&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;">:thumb</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;100x100#&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
validates_attachment_presence <span style="color:#ff3333; font-weight:bold;">:data</span>
validates_attachment_size <span style="color:#ff3333; font-weight:bold;">:data</span>, <span style="color:#ff3333; font-weight:bold;">:less_than</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">2</span>.<span style="color:#9900CC;">megabytes</span>  
validates_attachment_content_type <span style="color:#ff3333; font-weight:bold;">:data</span>, <span style="color:#ff3333; font-weight:bold;">:content_type</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'image/jpeg'</span>, <span style="color:#996600;">'image/jpg'</span>, <span style="color:#996600;">'image/png'</span>, <span style="color:#996600;">'image/gif'</span><span style="color:#006600; font-weight:bold;">&#93;</span></pre></td></tr></table></div>

<h2>Controllers</h2>
<p><strong>app/controllers/photos_controller.rb</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> PhotosController <span style="color:#006600; font-weight:bold;">&lt;</span> ApplicationController 
  <span style="color:#9966CC; font-weight:bold;">def</span> create
&nbsp;
    newparams = coerce<span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#41;</span> 
    <span style="color:#0066ff; font-weight:bold;">@photo</span> = Photo.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>newparams<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:upload</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> 
&nbsp;
    <span style="color:#006600; font-weight:bold;">//</span> so this photo can belong to other models other than album
    <span style="color:#0066ff; font-weight:bold;">@parent</span> = <span style="color:#0066ff; font-weight:bold;">@photo</span>.<span style="color:#9900CC;">parent</span>.<span style="color:#9900CC;">constantize</span>.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span>@photo.<span style="color:#9900CC;">attachable_id</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@photo</span>.<span style="color:#9900CC;">save</span>
      flash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:notice</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;Successfully uploaded photo.&quot;</span>
      respond_to <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>format<span style="color:#006600; font-weight:bold;">|</span> 
        <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">html</span> <span style="color:#006600; font-weight:bold;">&#123;</span>redirect_to <span style="color:#0066ff; font-weight:bold;">@parent</span><span style="color:#006600; font-weight:bold;">&#125;</span> 
        <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">json</span>  <span style="color:#006600; font-weight:bold;">&#123;</span> render <span style="color:#ff3333; font-weight:bold;">:json</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;">:result</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'success'</span>, <span style="color:#ff3333; font-weight:bold;">:upload</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> photo_path<span style="color:#006600; font-weight:bold;">&#40;</span>@photo<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#006600; font-weight:bold;">&#125;</span> 
      <span style="color:#9966CC; font-weight:bold;">end</span> 
    <span style="color:#9966CC; font-weight:bold;">else</span>
      flash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:notice</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;Only gif, jpg or png files allowed&quot;</span>
      respond_to <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>format<span style="color:#006600; font-weight:bold;">|</span> 
        <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">html</span> <span style="color:#006600; font-weight:bold;">&#123;</span>redirect_to <span style="color:#0066ff; font-weight:bold;">@parent</span><span style="color:#006600; font-weight:bold;">&#125;</span> 
        <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">json</span>  <span style="color:#006600; font-weight:bold;">&#123;</span> render <span style="color:#ff3333; font-weight:bold;">:json</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;">:result</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'failed'</span><span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#006600; font-weight:bold;">&#125;</span> 
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> show
    <span style="color:#0066ff; font-weight:bold;">@photo</span> = Photo.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:id</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>    
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> coerce<span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#41;</span> 
    <span style="color:#9966CC; font-weight:bold;">if</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:upload</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#0000FF; font-weight:bold;">nil</span>? 
      h = <span style="color:#CC00FF; font-weight:bold;">Hash</span>.<span style="color:#9900CC;">new</span> 
      h<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:upload</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#CC00FF; font-weight:bold;">Hash</span>.<span style="color:#9900CC;">new</span> 
      h<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:upload</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:attachable_id</span><span style="color:#006600; font-weight:bold;">&#93;</span> = params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:attachable_id</span><span style="color:#006600; font-weight:bold;">&#93;</span> 
      h<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:upload</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:parent</span><span style="color:#006600; font-weight:bold;">&#93;</span> = params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:parent</span><span style="color:#006600; font-weight:bold;">&#93;</span> 
      h<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:upload</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:data</span><span style="color:#006600; font-weight:bold;">&#93;</span> = params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:Filedata</span><span style="color:#006600; font-weight:bold;">&#93;</span> 
      h<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:upload</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:data</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">content_type</span> =  <span style="color:#6666ff; font-weight:bold;">MIME::Types</span>.<span style="color:#9900CC;">type_for</span><span style="color:#006600; font-weight:bold;">&#40;</span>h<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:upload</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:data</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">original_filename</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">to_s</span> 
      h 
    <span style="color:#9966CC; font-weight:bold;">else</span> 
      params 
    <span style="color:#9966CC; font-weight:bold;">end</span> 
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<h2>Views</h2>
<p><strong>app/views/albums/show.html.erb</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span>= stylesheet_link_tag <span style="color:#996600;">&quot;uploadify&quot;</span>  <span style="color:#006600; font-weight:bold;">%&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;%</span>= javascript_include_tag <span style="color:#996600;">&quot;uploadify/swfobject&quot;</span>, <span style="color:#996600;">&quot;uploadify/jquery.uploadify.v2.1.0.min.js&quot;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
&nbsp;
<span style="color:#006600; font-weight:bold;">&lt;%-</span> session_key_name = <span style="color:#6666ff; font-weight:bold;">ActionController::Base</span>.<span style="color:#9900CC;">session_options</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:key</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">-%&gt;</span>
&nbsp;
&lt;script type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;&gt; 
jQuery.noConflict();
&nbsp;
jQuery().ready(function() { 
   jQuery('#photo_upload').click(function(event){ 
      event.preventDefault(); 
   }); 
&nbsp;
  jQuery('#photo_upload').uploadify({ 
&nbsp;
    'uploader'    : '/javascripts/uploadify/uploadify.swf', 
    'script'      : '/cms/photos', 
    'multi'       : true, 
    'cancelImg' : '/photos/cancel.png',
&nbsp;
    onComplete : function(event, queueID, fileObj, response, data) { 
	var dat = eval('(' + response + ')'); 
	if (dat.result=='success'){
 	  jQuery.getScript(dat.upload);
        }else{
	  alert(&quot;Only .jpg, .gif, .png files under 2MB allowed. &quot;)
	}
    }, 
&nbsp;
    'scriptData' : { 'format' : 'json', 
      '<span style="color:#006600; font-weight:bold;">&lt;%</span>= session_key_name <span style="color:#006600; font-weight:bold;">%&gt;</span>' : encodeURIComponent('<span style="color:#006600; font-weight:bold;">&lt;%</span>= u cookies<span style="color:#006600; font-weight:bold;">&#91;</span>session_key_name<span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>'), 
      'authenticity_token' : encodeURIComponent('<span style="color:#006600; font-weight:bold;">&lt;%</span>= u form_authenticity_token <span style="color:#9966CC; font-weight:bold;">if</span> protect_against_forgery? <span style="color:#006600; font-weight:bold;">%&gt;</span>'), 
      'attachable_id' 	: '<span style="color:#006600; font-weight:bold;">&lt;%</span>= <span style="color:#0066ff; font-weight:bold;">@album</span>.<span style="color:#9900CC;">id</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>',
      'parent' 	: 'Album'} 
    }); 
    jQuery('#photo_submit').click(function(event){ 
      event.preventDefault(); 
      jQuery('#photo_upload').uploadifyUpload(); 
    }); 
  }); 
&lt;/script&gt;
&nbsp;
<span style="color:#006600; font-weight:bold;">&lt;%</span> form_for Image.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:attachable_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@deal</span>.<span style="color:#9900CC;">id</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#ff3333; font-weight:bold;">:html</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;">: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:#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>
	&lt;div class=&quot;image-uploader&quot;&gt;
		<span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">file_field</span> <span style="color:#ff3333; font-weight:bold;">:data</span>, <span style="color:#ff3333; font-weight:bold;">:id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'image_upload'</span>  <span style="color:#006600; font-weight:bold;">%&gt;</span>
		<span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">submit</span> <span style="color:#996600;">&quot;Upload Images&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'image_submit'</span><span style="color:#006600; font-weight:bold;">%&gt;</span>
	&lt;/div&gt;
<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></td></tr></table></div>

<h2>Resources</h2>
<p>Many thanks to the following articles that helped me figure out how to get this working<br />
Please follow the links for more detailed explanations</p>
<p><a href="http://fencore.posterous.com/uploadify-with-paperclip-on-rails-tutorial" target="_blank">http://fencore.posterous.com/uploadify-with-paperclip-on-rails-tutorial</a><br />
<a href="http://timmyc.posterous.com/uploadify-on-rails-with-paperclip" target="_blank">http://timmyc.posterous.com/uploadify-on-rails-with-paperclip</a><br />
<a href="http://www.practicalecommerce.com/blogs/post/432-Multiple-Attachments-in-Rails" target="_blank">http://www.practicalecommerce.com/blogs/post/432-Multiple-Attachments-in-Rails</a><br />
<a href="http://www.utoronto.ca/web/htmldocs/book/book-3ed/appb/mimetype.html" target="_blank">http://www.utoronto.ca/web/htmldocs/book/book-3ed/appb/mimetype.html</a><br />
<a href="http://en.wikipedia.org/wiki/Internet_media_type" target="_blank">http://en.wikipedia.org/wiki/Internet_media_type</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.skatercoder.com/2010/08/31/how-to-upload-multiple-files-on-rails-uploadify-paperclip-jquery/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>MySQL &#8211; Select rows from Table A that do not exist in Table B</title>
		<link>http://www.skatercoder.com/2009/03/25/mysql-select-rows-from-table-a-that-do-not-exist-in-table-b/</link>
		<comments>http://www.skatercoder.com/2009/03/25/mysql-select-rows-from-table-a-that-do-not-exist-in-table-b/#comments</comments>
		<pubDate>Wed, 25 Mar 2009 09:12:48 +0000</pubDate>
		<dc:creator>roadburn</dc:creator>
				<category><![CDATA[Coding Tips]]></category>

		<guid isPermaLink="false">http://roadburn.audioreload.com/?p=270</guid>
		<description><![CDATA[Here&#8217;s a useful MySQL code snippet: Select rows from table A that do not exist in table B 1 SELECT FROM A WHERE id NOT IN &#40;SELECT id FROM B&#41;]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a useful MySQL code snippet:</p>
<p>Select rows from table A that do not exist in table B</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">FROM</span> A <span style="color: #993333; font-weight: bold;">WHERE</span> id <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> id <span style="color: #993333; font-weight: bold;">FROM</span> B<span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.skatercoder.com/2009/03/25/mysql-select-rows-from-table-a-that-do-not-exist-in-table-b/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to: Install php zip on mac osx leopard</title>
		<link>http://www.skatercoder.com/2009/02/25/how-to-install-php-zip-on-mac-osx-leopard/</link>
		<comments>http://www.skatercoder.com/2009/02/25/how-to-install-php-zip-on-mac-osx-leopard/#comments</comments>
		<pubDate>Wed, 25 Feb 2009 08:41:15 +0000</pubDate>
		<dc:creator>roadburn</dc:creator>
				<category><![CDATA[Coding Tips]]></category>

		<guid isPermaLink="false">http://roadburn.audioreload.com/?p=266</guid>
		<description><![CDATA[Need to install PHP zip on your mac? It&#8217;s easy :) 1 $sudo pecl install zip]]></description>
			<content:encoded><![CDATA[<p>Need to install PHP zip on your mac?</p>
<p>It&#8217;s easy :)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">$sudo</span> pecl <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #c20cb9; font-weight: bold;">zip</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.skatercoder.com/2009/02/25/how-to-install-php-zip-on-mac-osx-leopard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Set MySQL default charset to UTF8</title>
		<link>http://www.skatercoder.com/2009/01/31/set-mysql-default-charset-to-utf8/</link>
		<comments>http://www.skatercoder.com/2009/01/31/set-mysql-default-charset-to-utf8/#comments</comments>
		<pubDate>Sat, 31 Jan 2009 16:42:36 +0000</pubDate>
		<dc:creator>roadburn</dc:creator>
				<category><![CDATA[Coding Tips]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[utf8]]></category>

		<guid isPermaLink="false">http://roadburn.audioreload.com/?p=257</guid>
		<description><![CDATA[In the /etc/my.cnf file add 1 2 3 4 5 6 7 8 9 10 &#91;mysqld&#93; # # * Basic Settings # &#160; # utf8 init-connect='SET NAMES utf8' character-set-server=utf8 collation-server=utf8_general_ci default-collation=utf8_general_ci]]></description>
			<content:encoded><![CDATA[<p>In the /etc/my.cnf file add</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>mysqld<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># * Basic Settings</span>
<span style="color: #666666; font-style: italic;">#</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># utf8</span>
init-connect=<span style="color: #ff0000;">'SET NAMES utf8'</span>
character-set-server=utf8
collation-server=utf8_general_ci
default-collation=utf8_general_ci</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.skatercoder.com/2009/01/31/set-mysql-default-charset-to-utf8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Install webmin on ubuntu</title>
		<link>http://www.skatercoder.com/2008/07/23/install-webmin-on-ubuntu/</link>
		<comments>http://www.skatercoder.com/2008/07/23/install-webmin-on-ubuntu/#comments</comments>
		<pubDate>Wed, 23 Jul 2008 02:57:22 +0000</pubDate>
		<dc:creator>roadburn</dc:creator>
				<category><![CDATA[Coding Tips]]></category>

		<guid isPermaLink="false">http://roadburn.audioreload.com/?p=210</guid>
		<description><![CDATA[http://onlyubuntu.blogspot.com/2007/05/how-to-install-webmin-in-ubuntu.html wget http://prdownloads.sourceforge.net/webadmin/webmin_1.340_all.deb sudo dpkg -i webmin_1.340_all.deb If libraries are missing.. sudo apt- get install -f]]></description>
			<content:encoded><![CDATA[<p><a href="http://onlyubuntu.blogspot.com/2007/05/how-to-install-webmin-in-ubuntu.html">http://onlyubuntu.blogspot.com/2007/05/how-to-install-webmin-in-ubuntu.html</a></p>
<p><span class="fullpost">wget http://prdownloads.sourceforge.net/webadmin/webmin_1.340_all.deb<br />
</span></p>
<p><span class="fullpost">sudo dpkg -i webmin_1.340_all.deb</p>
<p>If libraries are missing..</span></p>
<p><span class="fullpost">sudo apt- get install -f</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.skatercoder.com/2008/07/23/install-webmin-on-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

