<?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</title>
	<atom:link href="http://www.skatercoder.com/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>Thu, 02 Sep 2010 16:41:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>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 &#038; Database 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 Start server with debugging enabled $ script/server --debugger &#160; Start server with debugging enabled - specify environment $ script/server --debugger RAILS_ENV=production &#160; [...]]]></description>
			<content:encoded><![CDATA[<h2>Rails &#038; Database</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
30
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">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;
&nbsp;
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
&nbsp;
Install required gems
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> rake gem:<span style="color: #c20cb9; font-weight: bold;">install</span>
&nbsp;
View routes 
$ rake routes
&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</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
</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>
&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;
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>

]]></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 migration with the following:</p>
<p><strong>db/migrate/create_images.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> CreateImages <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;">:images</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> 2.<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></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>0</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> git:<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> git:<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> UserMailer <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>0</slash:comments>
		</item>
		<item>
		<title>Tricolor rice bowl success!</title>
		<link>http://www.skatercoder.com/2010/07/22/tricolor-rice-bowl-success/</link>
		<comments>http://www.skatercoder.com/2010/07/22/tricolor-rice-bowl-success/#comments</comments>
		<pubDate>Thu, 22 Jul 2010 04:34:17 +0000</pubDate>
		<dc:creator>roadburn</dc:creator>
				<category><![CDATA[Food]]></category>
		<category><![CDATA[food]]></category>

		<guid isPermaLink="false">http://roadburn.audioreload.com/2010/07/22/tricolor-rice-bowl-success/</guid>
		<description><![CDATA[Was inspired to cook today :) Found out how to make the sweet japanese style omelette, it was surprisingly easy! Ingredients: 2 eggs 2 tsp sugar Dash of salt Mirin Fresh ginger juice Olive oil Steps: Beat eggs and mix in the ginger juice,  sugar, salt and mirin Heat oil in small frying pan, I [...]]]></description>
			<content:encoded><![CDATA[<p>Was inspired to cook today :)</p>
<p><img class="alignnone size-medium wp-image-356" title="l_2048_1536_082866E7-9A20-4AF7-A7A0-B38F77404E3E.jpeg" src="/wp-content/uploads/2010/07/l_2048_1536_082866E7-9A20-4AF7-A7A0-B38F77404E3E-600x450.jpg" alt="" width="600" height="450" /></p>
<p>Found out how to make the sweet japanese style omelette, it was surprisingly easy!</p>
<p>Ingredients:</p>
<ul>
<li> 2 eggs</li>
<li>2 tsp sugar</li>
<li>Dash of salt</li>
<li>Mirin</li>
<li>Fresh ginger juice</li>
<li>Olive oil</li>
</ul>
<p>Steps:</p>
<ol>
<li>Beat eggs and mix in the ginger juice,  sugar, salt and mirin</li>
<li>Heat oil in small frying pan, I used those really small frying pans they sell to make the perfect sunny side up egg.</li>
<li>Pour the egg mixture into the frying pan and stir it so that it&#8217;s slightly scrambled, but don&#8217;t stir it too much or you will end up with scrambled eggs instead.</li>
<li>Let the eggs cook till it&#8217;s slightly brown on the bottom, then carefully flip it over to cook the other side.</li>
<li>That&#8217;s all!</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.skatercoder.com/2010/07/22/tricolor-rice-bowl-success/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>www.wendyphua.com</title>
		<link>http://www.skatercoder.com/2010/07/21/new-site-launch-www-wendyphua-com/</link>
		<comments>http://www.skatercoder.com/2010/07/21/new-site-launch-www-wendyphua-com/#comments</comments>
		<pubDate>Wed, 21 Jul 2010 05:43:56 +0000</pubDate>
		<dc:creator>roadburn</dc:creator>
				<category><![CDATA[Portfolio]]></category>

		<guid isPermaLink="false">http://roadburn.audioreload.com/?p=329</guid>
		<description><![CDATA[Just recently launched a WordPress website for a very talented Singaporean bassist and composer, Wendy Phua. Check out her site at www.wendyphua.com!]]></description>
			<content:encoded><![CDATA[<p>Just recently launched a WordPress website for a very talented Singaporean bassist and composer, Wendy Phua. </p>
<p>Check out her site at <a href="http://www.wendyphua.com" target="_blank">www.wendyphua.com</a>! </p>
<p><a href="http://www.wendyphua.com" target="_blank"><img src="/wp-content/uploads/2010/07/wendyphua1-600x412.jpg" alt="" title="wendyphua" width="600" height="412" class="alignnone size-medium wp-image-333" /></a> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.skatercoder.com/2010/07/21/new-site-launch-www-wendyphua-com/feed/</wfw:commentRss>
		<slash:comments>0</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>Create a self-signed SSL certificate with IIS 6.0 Resource Kit SelfSSL</title>
		<link>http://www.skatercoder.com/2009/07/23/create-a-self-signed-ssl-certificate-with-iis-6-0-resource-kit-selfssl/</link>
		<comments>http://www.skatercoder.com/2009/07/23/create-a-self-signed-ssl-certificate-with-iis-6-0-resource-kit-selfssl/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 02:58:06 +0000</pubDate>
		<dc:creator>roadburn</dc:creator>
				<category><![CDATA[Sharepoint]]></category>

		<guid isPermaLink="false">http://roadburn.audioreload.com/?p=84</guid>
		<description><![CDATA[ Internet Information Services (IIS) 6.0 Resource Kit Tools http://www.microsoft.com/downloads/details.aspx?FamilyID=56fc92ee-a71a-4c73-b628-ade629c89499&#38;displaylang=en]]></description>
			<content:encoded><![CDATA[<p> Internet Information Services (IIS) 6.0 Resource Kit Tools</p>
<p><a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=56fc92ee-a71a-4c73-b628-ade629c89499&amp;displaylang=en">http://www.microsoft.com/downloads/details.aspx?FamilyID=56fc92ee-a71a-4c73-b628-ade629c89499&amp;displaylang=en</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.skatercoder.com/2009/07/23/create-a-self-signed-ssl-certificate-with-iis-6-0-resource-kit-selfssl/feed/</wfw:commentRss>
		<slash:comments>0</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>
	</channel>
</rss>
