<?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; Rails</title>
	<atom:link href="http://www.skatercoder.com/category/rails/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>Debugging script/runner</title>
		<link>http://www.skatercoder.com/2011/03/21/debugging-scriptrunner/</link>
		<comments>http://www.skatercoder.com/2011/03/21/debugging-scriptrunner/#comments</comments>
		<pubDate>Mon, 21 Mar 2011 12:12:58 +0000</pubDate>
		<dc:creator>roadburn</dc:creator>
				<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://www.skatercoder.com/?p=494</guid>
		<description><![CDATA[If you need to debug script/runner 1 2 $ sudo gem install ruby-debug $ rdebug script/runner script.rb References http://cheat.errtheblog.com/s/rdebug/]]></description>
			<content:encoded><![CDATA[<p>If you need to debug script/runner</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;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> ruby-debug
$ rdebug script<span style="color: #000000; font-weight: bold;">/</span>runner script.rb</pre></td></tr></table></div>

<p>References<br />
<a href="http://cheat.errtheblog.com/s/rdebug/" target="_blank">http://cheat.errtheblog.com/s/rdebug/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.skatercoder.com/2011/03/21/debugging-scriptrunner/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>Comma Separated List in Rails</title>
		<link>http://www.skatercoder.com/2010/07/25/comma-separated-list-in-rails/</link>
		<comments>http://www.skatercoder.com/2010/07/25/comma-separated-list-in-rails/#comments</comments>
		<pubDate>Sat, 24 Jul 2010 17:14:01 +0000</pubDate>
		<dc:creator>roadburn</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[l]]></category>

		<guid isPermaLink="false">http://www.skatercoder.com/?p=391</guid>
		<description><![CDATA[Here&#8217;s a useful tip I found from http://ariejan.net/2007/03/27/rails-tip-snippet-create-a-comma-seperate-list/ To get &#8216;Tom, Dick, Harry&#8217; 1 @users.collect&#123;&#124;u&#124; u.name&#125;.join&#40;', '&#41; To get &#8216;Tom, Dick and Harry&#8217; 1 @users.collect&#40;&#38;:name&#41;.to_sentence]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a useful tip I found from <a href="http://ariejan.net/2007/03/27/rails-tip-snippet-create-a-comma-seperate-list/">http://ariejan.net/2007/03/27/rails-tip-snippet-create-a-comma-seperate-list/</a></p>
<p>To get &#8216;Tom, Dick, Harry&#8217;</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:#0066ff; font-weight:bold;">@users</span>.<span style="color:#9900CC;">collect</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>u<span style="color:#006600; font-weight:bold;">|</span> u.<span style="color:#9900CC;">name</span><span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">', '</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></td></tr></table></div>

<p>To get &#8216;Tom, Dick and Harry&#8217;</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:#0066ff; font-weight:bold;">@users</span>.<span style="color:#9900CC;">collect</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&amp;</span>:name<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">to_sentence</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.skatercoder.com/2010/07/25/comma-separated-list-in-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to: Create a Rails model that has categories and subcategories</title>
		<link>http://www.skatercoder.com/2010/07/23/how-to-create-a-rails-model-that-has-categories-and-subcategories/</link>
		<comments>http://www.skatercoder.com/2010/07/23/how-to-create-a-rails-model-that-has-categories-and-subcategories/#comments</comments>
		<pubDate>Fri, 23 Jul 2010 05:57:37 +0000</pubDate>
		<dc:creator>roadburn</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[acts_as_tree]]></category>
		<category><![CDATA[categories]]></category>

		<guid isPermaLink="false">http://www.skatercoder.com/?p=384</guid>
		<description><![CDATA[Another reason to love rails, it&#8217;s so easy! Just install the acts_as_tree plugin 1 $ script/plugin install git://github.com/rails/acts_as_tree.git and in your model, eg. app/models/category.rb, just add 1 acts_as_tree :order =&#62; 'name' And here&#8217;s the plugin&#8217;s readme on how to use it 1 2 3 4 5 6 7 8 9 10 11 12 13 14 [...]]]></description>
			<content:encoded><![CDATA[<p>Another reason to love rails, it&#8217;s so easy!</p>
<p>Just install the <a href="http://github.com/rails/acts_as_tree" target="_blank">acts_as_tree plugin</a></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;">$ script<span style="color: #000000; font-weight: bold;">/</span>plugin <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #c20cb9; font-weight: bold;">git</span>:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>rails<span style="color: #000000; font-weight: bold;">/</span>acts_as_tree.git</pre></td></tr></table></div>

<p>and in your model, eg. <strong>app/models/category.rb</strong>, just add</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;">acts_as_tree <span style="color:#ff3333; font-weight:bold;">:order</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'name'</span></pre></td></tr></table></div>

<p>And here&#8217;s the plugin&#8217;s readme on how to use it</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
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">acts_as_tree
============
&nbsp;
Specify this <span style="color:#006600; font-weight:bold;">+</span>acts_as<span style="color:#006600; font-weight:bold;">+</span> extension <span style="color:#9966CC; font-weight:bold;">if</span> you want to model a tree structure by providing a parent association <span style="color:#9966CC; font-weight:bold;">and</span> a children
association. <span style="color:#9900CC;">This</span> requires that you have a foreign key column, which by default is called <span style="color:#006600; font-weight:bold;">+</span>parent_id<span style="color:#006600; font-weight:bold;">+</span>.
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">class</span> Category <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
    acts_as_tree <span style="color:#ff3333; font-weight:bold;">:order</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;name&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  Example:
  root
   \_ child1
        \_ subchild1
        \_ subchild2
&nbsp;
  root      = Category.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;name&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;root&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  child1    = root.<span style="color:#9900CC;">children</span>.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;name&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;child1&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  subchild1 = child1.<span style="color:#9900CC;">children</span>.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;name&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;subchild1&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
  root.<span style="color:#9900CC;">parent</span>   <span style="color:#008000; font-style:italic;"># =&gt; nil</span>
  child1.<span style="color:#9900CC;">parent</span> <span style="color:#008000; font-style:italic;"># =&gt; root</span>
  root.<span style="color:#9900CC;">children</span> <span style="color:#008000; font-style:italic;"># =&gt; [child1]</span>
  root.<span style="color:#9900CC;">children</span>.<span style="color:#9900CC;">first</span>.<span style="color:#9900CC;">children</span>.<span style="color:#9900CC;">first</span> <span style="color:#008000; font-style:italic;"># =&gt; subchild1</span></pre></td></tr></table></div>

<p><strong>Resources</strong></p>
<ul>
<li><a href="http://railscasts.com/episodes/162-tree-based-navigation" target="_blank">Railscasts &#8211; Tree Based Navigation</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.skatercoder.com/2010/07/23/how-to-create-a-rails-model-that-has-categories-and-subcategories/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to: Receive email in rails with mail fetcher</title>
		<link>http://www.skatercoder.com/2010/07/23/how-to-receive-email-in-rails-with-mail-fetcher/</link>
		<comments>http://www.skatercoder.com/2010/07/23/how-to-receive-email-in-rails-with-mail-fetcher/#comments</comments>
		<pubDate>Thu, 22 Jul 2010 16:46:26 +0000</pubDate>
		<dc:creator>roadburn</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[action mailer]]></category>
		<category><![CDATA[mail fetcher]]></category>
		<category><![CDATA[receive email]]></category>

		<guid isPermaLink="false">http://roadburn.audioreload.com/?p=362</guid>
		<description><![CDATA[Dan Weinand and Luke Francl have written a nice plugin which simplifies the task of retrieving emails. Kudos to them! So basically what you need to do is install the plugin, create the Action Mailer receiver, and then use cron to schedule the script to run Here are the steps: First install the fetcher plugin [...]]]></description>
			<content:encoded><![CDATA[<p>Dan Weinand and Luke Francl have written a nice plugin which simplifies the task of retrieving emails. Kudos to them!</p>
<p>So basically what you need to do is install the plugin, create the Action Mailer receiver, and then use cron to schedule the script to run</p>
<p>Here are the steps:</p>
<p>First install the fetcher plugin from <a href="http://github.com/look/fetcher/" target="_blank">http://github.com/look/fetcher/</a> and SystemTimer gem it requires</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ script<span style="color: #000000; font-weight: bold;">/</span>plugin <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #c20cb9; font-weight: bold;">git</span>:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>look<span style="color: #000000; font-weight: bold;">/</span>fetcher.git
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> SystemTimer</pre></div></div>

<p>Create your ruby script eg. <strong>script/mail_fetcher</strong></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#!/usr/bin/env ruby</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">dirname</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">'/../config/environment.rb'</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'system_timer'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'yaml'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'fetcher'</span>
&nbsp;
&nbsp;
<span style="color:#9966CC; font-weight:bold;">begin</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Start checking email&quot;</span>
&nbsp;
  Lockfile.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'cron_mail_fetcher.lock'</span>, <span style="color:#ff3333; font-weight:bold;">:retries</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    config = <span style="color:#CC00FF; font-weight:bold;">YAML</span>.<span style="color:#9900CC;">load_file</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;#{RAILS_ROOT}/config/mail.yml&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    config = config<span style="color:#006600; font-weight:bold;">&#91;</span>RAILS_ENV<span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">to_options</span>
&nbsp;
    fetcher = Fetcher.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#123;</span>:receiver <span style="color:#006600; font-weight:bold;">=&gt;</span> EnquiryMailer<span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">merge</span><span style="color:#006600; font-weight:bold;">&#40;</span>config<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    fetcher.<span style="color:#9900CC;">fetch</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#6666ff; font-weight:bold;">Lockfile::MaxTriesLockError</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> e
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Another fetcher is already running. Exiting.&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Create the <strong>config/mail.yml</strong> file</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">defaults: <span style="color:#006600; font-weight:bold;">&amp;</span>defaults
  <span style="color:#008000; font-style:italic;"># Settings for gmail</span>
  type: imap                <span style="color:#008000; font-style:italic;"># pop OR imap</span>
  server: imap.<span style="color:#9900CC;">gmail</span>.<span style="color:#9900CC;">com</span>  <span style="color:#008000; font-style:italic;"># server hostname</span>
  port: <span style="color:#006666;">993</span>                 <span style="color:#008000; font-style:italic;"># 993 for IMAPs</span>
  ssl: <span style="color:#0000FF; font-weight:bold;">true</span>                 <span style="color:#008000; font-style:italic;"># Remove if not using SSL</span>
  username: user@gmail.<span style="color:#9900CC;">com</span>    <span style="color:#008000; font-style:italic;"># Username</span>
  password: xxx                <span style="color:#008000; font-style:italic;"># Password</span>
  use_login: <span style="color:#0000FF; font-weight:bold;">true</span>           <span style="color:#008000; font-style:italic;"># Required for GMAIL</span>
  processed_folder: processed
  error_folder: error
&nbsp;
 <span style="color:#008000; font-style:italic;"># settings for bluehost</span>
  type: imap                <span style="color:#008000; font-style:italic;"># pop OR imap</span>
  server: boxXXX.<span style="color:#9900CC;">bluehost</span>.<span style="color:#9900CC;">com</span>  <span style="color:#008000; font-style:italic;"># server hostname</span>
  port: <span style="color:#006666;">993</span>                 <span style="color:#008000; font-style:italic;"># 993 for IMAPs</span>
  ssl: <span style="color:#0000FF; font-weight:bold;">true</span>                 <span style="color:#008000; font-style:italic;"># Remove if not using SSL</span>
  username: user@domain.<span style="color:#9900CC;">com</span>    <span style="color:#008000; font-style:italic;"># Username</span>
  password: xxx                <span style="color:#008000; font-style:italic;"># Password</span>
  use_login: <span style="color:#0000FF; font-weight:bold;">true</span>
  processed_folder: INBOX.<span style="color:#9900CC;">processed</span>
  error_folder: INBOX.<span style="color:#9900CC;">error</span>
&nbsp;
development:
  <span style="color:#006600; font-weight:bold;">&lt;&lt;</span>: <span style="color:#006600; font-weight:bold;">*</span>defaults
  <span style="color:#008000; font-style:italic;"># Override other values here</span>
&nbsp;
test:
  <span style="color:#006600; font-weight:bold;">&lt;&lt;</span>: <span style="color:#006600; font-weight:bold;">*</span>defaults
  <span style="color:#008000; font-style:italic;"># Override other values here</span>
&nbsp;
production:
  <span style="color:#006600; font-weight:bold;">&lt;&lt;</span>: <span style="color:#006600; font-weight:bold;">*</span>defaults
  <span style="color:#008000; font-style:italic;"># Override other values here</span></pre></div></div>

<p>Create your Action Mailer</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ script<span style="color: #000000; font-weight: bold;">/</span>generate mailer EnquiryMailer</pre></div></div>

<p>Add the receiver in <strong>app/models/enquiry_mailer.rb</strong></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> EnquiryMailer <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActionMailer::Base</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> receive<span style="color:#006600; font-weight:bold;">&#40;</span>email<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#008000; font-style:italic;"># do whatever you want with the email here</span>
    <span style="color:#008000; font-style:italic;"># you can use:</span>
    <span style="color:#008000; font-style:italic;"># email.subject, email.from, email.body</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Run the script</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ script<span style="color: #000000; font-weight: bold;">/</span>runner script<span style="color: #000000; font-weight: bold;">/</span>mail_fetcher</pre></div></div>

<p>Then follow Ryan Bate&#8217;s screencast on how to use <a href="http://railscasts.com/episodes/164-cron-in-ruby" target="blank">Cron in Ruby</a></p>
<p><strong>Resources</strong></p>
<ul>
<li><a href="http://guides.rubyonrails.org/action_mailer_basics.html" target="_blank">http://guides.rubyonrails.org/action_mailer_basics.html</a></li>
<li><a href="http://railspikes.com/2007/6/1/rails-email-processing" target="_blank">http://railspikes.com/2007/6/1/rails-email-processing</a></li>
<li><a href="http://railscasts.com/episodes/164-cron-in-ruby" target="blank">Railscasts: Cron in Ruby</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.skatercoder.com/2010/07/23/how-to-receive-email-in-rails-with-mail-fetcher/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Rails fetcher mail.yml IMAP setting for bluehost</title>
		<link>http://www.skatercoder.com/2010/07/21/rails-fetcher-mail-yml-imap-setting-for-bluehost/</link>
		<comments>http://www.skatercoder.com/2010/07/21/rails-fetcher-mail-yml-imap-setting-for-bluehost/#comments</comments>
		<pubDate>Tue, 20 Jul 2010 18:42:40 +0000</pubDate>
		<dc:creator>roadburn</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[bluehost]]></category>
		<category><![CDATA[fetcher]]></category>
		<category><![CDATA[imap]]></category>

		<guid isPermaLink="false">http://roadburn.audioreload.com/?p=302</guid>
		<description><![CDATA[I was getting this error when trying to create a mailbox using create(mailbox) from Net::IMAP 1 /opt/local/lib/ruby/1.8/net/imap.rb:981:in `pick_up_tagged_response': Unknown namespace. (Net::IMAP::NoResponseError) Realised that the processed and error mailboxes names had to be appended to &#8220;INBOX.&#8221; 1 2 3 4 5 6 7 8 9 type: imap server: boxXXX.bluehost.com port: 993 ssl: true username: username@domain.com password: [...]]]></description>
			<content:encoded><![CDATA[<p>I was getting this error when trying to create a mailbox using create(mailbox) from Net::IMAP</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: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>net<span style="color: #000000; font-weight: bold;">/</span>imap.rb:<span style="color: #000000;">981</span>:<span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span>pick_up_tagged_response<span style="color: #ff0000;">': Unknown namespace. (Net::IMAP::NoResponseError)</span></pre></td></tr></table></div>

<p>Realised that the processed and error mailboxes names had to be appended to &#8220;INBOX.&#8221;</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;">type: imap            
server: boxXXX.<span style="color:#9900CC;">bluehost</span>.<span style="color:#9900CC;">com</span>  
port: <span style="color:#006666;">993</span>                
ssl: <span style="color:#0000FF; font-weight:bold;">true</span>               
username: username@domain.<span style="color:#9900CC;">com</span> 
password: xxx
use_login: <span style="color:#0000FF; font-weight:bold;">true</span>        
processed_folder: INBOX.<span style="color:#9900CC;">processed</span>
error_folder: INBOX.<span style="color:#9900CC;">error</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.skatercoder.com/2010/07/21/rails-fetcher-mail-yml-imap-setting-for-bluehost/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to: Install Memcached on Ubuntu for Rails</title>
		<link>http://www.skatercoder.com/2009/02/18/installing-memcached-on-ubuntu-for-rails/</link>
		<comments>http://www.skatercoder.com/2009/02/18/installing-memcached-on-ubuntu-for-rails/#comments</comments>
		<pubDate>Wed, 18 Feb 2009 04:16:02 +0000</pubDate>
		<dc:creator>roadburn</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[memcached]]></category>

		<guid isPermaLink="false">http://roadburn.audioreload.com/?p=260</guid>
		<description><![CDATA[1 2 3 4 5 6 7 sudo aptitude install memcached &#160; sudo aptitude install libmemcache-dev &#160; sudo gem install RubyInline &#160; sudo gem install memcache-client in application.rb Uncomment the protect_from_forgery in environment.rb 1 2 3 4 5 6 7 8 9 CACHE = MemCache.new 'localhost:11211', :namespace =&#38;gt; 'your_app' &#160; config.action_controller.session = &#123; :session_key =&#62; [...]]]></description>
			<content:encoded><![CDATA[
<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;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> memcached
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> libmemcache-dev
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> RubyInline
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> memcache-client</pre></td></tr></table></div>

<p><strong>in application.rb</strong></p>
<p>Uncomment the protect_from_forgery</p>
<p><strong>in 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;">CACHE = MemCache.<span style="color:#9900CC;">new</span> <span style="color:#996600;">'localhost:11211'</span>, <span style="color:#ff3333; font-weight:bold;">:namespace</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">'your_app'</span>
&nbsp;
config.<span style="color:#9900CC;">action_controller</span>.<span style="color:#9900CC;">session</span> = <span style="color:#006600; font-weight:bold;">&#123;</span>
<span style="color:#ff3333; font-weight:bold;">:session_key</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'_your_app_session'</span>,
<span style="color:#ff3333; font-weight:bold;">:secret</span>      <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'yoursecrectkey'</span>,
<span style="color:#ff3333; font-weight:bold;">:cache</span>       <span style="color:#006600; font-weight:bold;">=&gt;</span> CACHE,
<span style="color:#ff3333; font-weight:bold;">:expires</span><span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">900</span>  <span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
config.<span style="color:#9900CC;">action_controller</span>.<span style="color:#9900CC;">session_store</span> = <span style="color:#ff3333; font-weight:bold;">:mem_cache_store</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.skatercoder.com/2009/02/18/installing-memcached-on-ubuntu-for-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Attach images in rails</title>
		<link>http://www.skatercoder.com/2008/12/25/attach-images-in-rails/</link>
		<comments>http://www.skatercoder.com/2008/12/25/attach-images-in-rails/#comments</comments>
		<pubDate>Thu, 25 Dec 2008 08:01:16 +0000</pubDate>
		<dc:creator>roadburn</dc:creator>
				<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://roadburn.audioreload.com/?p=253</guid>
		<description><![CDATA[View the railscast on using thoughtbot&#8217;s paperclip http://railscasts.com/episodes/134-paperclip or attach multiple images to a model using polymorphic paperclip http://burm.net/2008/10/17/ruby-on-rails-polymorphic-paperclip-plugin-tutorial/]]></description>
			<content:encoded><![CDATA[<p>View the railscast on using thoughtbot&#8217;s paperclip</p>
<p><a href="http://railscasts.com/episodes/134-paperclip">http://railscasts.com/episodes/134-paperclip</a></p>
<p>or</p>
<p>attach multiple images to a model using polymorphic paperclip</p>
<p><a href="http://burm.net/2008/10/17/ruby-on-rails-polymorphic-paperclip-plugin-tutorial/">http://burm.net/2008/10/17/ruby-on-rails-polymorphic-paperclip-plugin-tutorial/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.skatercoder.com/2008/12/25/attach-images-in-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

