<?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>mobile and gis dev notes &#187; ruby</title>
	<atom:link href="http:///wordpress/tag/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>/wordpress</link>
	<description>by rupert</description>
	<lastBuildDate>Wed, 08 Feb 2012 22:26:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>please install libyaml and reinstall your ruby.</title>
		<link>/wordpress/2012/02/please-install-libyaml-and-reinstall-your-ruby/</link>
		<comments>/wordpress/2012/02/please-install-libyaml-and-reinstall-your-ruby/#comments</comments>
		<pubDate>Wed, 08 Feb 2012 00:01:25 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[rvm]]></category>

		<guid isPermaLink="false">/wordpress/?p=1232</guid>
		<description><![CDATA[/Users/rupert/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/yaml.rb:56:in `&#60;top (required)&#62;': It seems your ruby installation is missing psych (for YAML output). To eliminate this warning, please install libyaml and reinstall your ruby. ~% rvm remove ruby-1.9.3-p0 Removing /Users/rupert/.rvm/src/ruby-1.9.3-p0... Removing /Users/rupert/.rvm/rubies/ruby-1.9.3-p0... Removing ruby-1.9.3-p0 aliases... Removing ruby-1.9.3-p0 wrappers... Removing ruby-1.9.3-p0 environments... Removing ruby-1.9.3-p0 binaries... ~% rvm list rvm rubies &#160; ruby-1.8.7-p302 [ x86_64 ] [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">/Users/rupert/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/yaml.rb:56:in `&lt;top (required)&gt;':
It seems your ruby installation is missing psych (for YAML output).
To eliminate this warning, please install libyaml and reinstall your ruby.</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">~% rvm remove ruby-1.9.3-p0
Removing /Users/rupert/.rvm/src/ruby-1.9.3-p0...
Removing /Users/rupert/.rvm/rubies/ruby-1.9.3-p0...
Removing ruby-1.9.3-p0 aliases...
Removing ruby-1.9.3-p0 wrappers...
Removing ruby-1.9.3-p0 environments...
Removing ruby-1.9.3-p0 binaries...</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">~% rvm list
rvm rubies
&nbsp;
   ruby-1.8.7-p302 [ x86_64 ]
   ruby-1.9.2-p0 [ x86_64 ]
=&gt; ruby-1.9.2-p180 [ x86_64 ]</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">~% rvm install ruby-1.9.3-p0
/Users/rupert/.rvm/rubies/ruby-1.9.3-p0, this may take a while depending on your cpu(s)...
&nbsp;
ruby-1.9.3-p0 - #fetching 
ruby-1.9.3-p0 - #extracting ruby-1.9.3-p0 to /Users/rupert/.rvm/src/ruby-1.9.3-p0
ruby-1.9.3-p0 - #extracted to /Users/rupert/.rvm/src/ruby-1.9.3-p0
ruby-1.9.3-p0 - #configuring 
ruby-1.9.3-p0 - #compiling 
ruby-1.9.3-p0 - #installing 
ruby-1.9.3-p0 - updating #rubygems for /Users/rupert/.rvm/gems/ruby-1.9.3-p0@global
ruby-1.9.3-p0 - updating #rubygems for /Users/rupert/.rvm/gems/ruby-1.9.3-p0
ruby-1.9.3-p0 - adjusting #shebangs for (gem).
ruby-1.9.3-p0 - #importing default gemsets (/Users/rupert/.rvm/gemsets/)</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">~% rvm list
&nbsp;
rvm rubies
&nbsp;
   ruby-1.8.7-p302 [ x86_64 ]
   ruby-1.9.2-p0 [ x86_64 ]
=&gt; ruby-1.9.2-p180 [ x86_64 ]
   ruby-1.9.3-p0 [ x86_64 ]</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">~% rvm use ruby-1.9.3-p0
Using /Users/rupert/.rvm/gems/ruby-1.9.3-p0</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">~/current[master]% gem list
&nbsp;
*** LOCAL GEMS ***
&nbsp;
rake (0.9.2.2)
rubygems-update (1.8.15)</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2012/02/please-install-libyaml-and-reinstall-your-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Invalid gemspec on what?!</title>
		<link>/wordpress/2011/09/invalid-gemspec-on-what/</link>
		<comments>/wordpress/2011/09/invalid-gemspec-on-what/#comments</comments>
		<pubDate>Wed, 14 Sep 2011 06:15:58 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[rubyonrails]]></category>

		<guid isPermaLink="false">/wordpress/?p=1070</guid>
		<description><![CDATA[This belongs to a royal PITA moment, thus needs a worthy post. I&#8217;m trying to do a bundle install with my Gemfile as follows: group :development, :test do gem 'capybara' gem 'cucumber' gem 'cucumber-rails' gem 'database_cleaner' gem 'rspec-rails' gem 'autotest' gem 'spork' gem 'launchy' end At the time of writing this, these are the errors [...]]]></description>
			<content:encoded><![CDATA[<p>This belongs to a royal PITA moment, thus needs a worthy post. I&#8217;m trying to do a</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">bundle <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>with my Gemfile as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">group <span style="color:#ff3333; font-weight:bold;">:development</span>, <span style="color:#ff3333; font-weight:bold;">:test</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  gem <span style="color:#996600;">'capybara'</span>
  gem <span style="color:#996600;">'cucumber'</span>
  gem <span style="color:#996600;">'cucumber-rails'</span>
  gem <span style="color:#996600;">'database_cleaner'</span>
  gem <span style="color:#996600;">'rspec-rails'</span>
  gem <span style="color:#996600;">'autotest'</span>
  gem <span style="color:#996600;">'spork'</span>
  gem <span style="color:#996600;">'launchy'</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>At the time of writing this, these are the errors that I encountered.  Since you are reading this, then I guess something is still wrong here.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Installing cucumber <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.0.6<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Installing cucumber-rails <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.0.4<span style="color: #7a0874; font-weight: bold;">&#41;</span> Invalid gemspec <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>.rvm<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>ruby-1.9.2-p180<span style="color: #000000; font-weight: bold;">@</span>cws<span style="color: #000000; font-weight: bold;">/</span>specifications<span style="color: #000000; font-weight: bold;">/</span>cucumber-rails-1.0.4.gemspec<span style="color: #7a0874; font-weight: bold;">&#93;</span>: Illformed requirement <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;#&lt;Syck::DefaultKey:0x00000104b82a40&gt; 0.7.2&quot;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
Installing database_cleaner <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.6.7<span style="color: #7a0874; font-weight: bold;">&#41;</span> Invalid gemspec <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>.rvm<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>ruby-1.9.2-p180<span style="color: #000000; font-weight: bold;">@</span>cws<span style="color: #000000; font-weight: bold;">/</span>specifications<span style="color: #000000; font-weight: bold;">/</span>cucumber-rails-1.0.4.gemspec<span style="color: #7a0874; font-weight: bold;">&#93;</span>: Illformed requirement <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;#&lt;Syck::DefaultKey:0x00000104b82a40&gt; 0.7.2&quot;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
Installing orm_adapter <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.0.5<span style="color: #7a0874; font-weight: bold;">&#41;</span> Invalid gemspec <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>.rvm<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>ruby-1.9.2-p180<span style="color: #000000; font-weight: bold;">@</span>cws<span style="color: #000000; font-weight: bold;">/</span>specifications<span style="color: #000000; font-weight: bold;">/</span>cucumber-rails-1.0.4.gemspec<span style="color: #7a0874; font-weight: bold;">&#93;</span>: Illformed requirement <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;#&lt;Syck::DefaultKey:0x00000104b82a40&gt; 0.7.2&quot;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
Installing warden <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.0.5<span style="color: #7a0874; font-weight: bold;">&#41;</span> Invalid gemspec <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>.rvm<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>ruby-1.9.2-p180<span style="color: #000000; font-weight: bold;">@</span>cws<span style="color: #000000; font-weight: bold;">/</span>specifications<span style="color: #000000; font-weight: bold;">/</span>cucumber-rails-1.0.4.gemspec<span style="color: #7a0874; font-weight: bold;">&#93;</span>: Illformed requirement <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;#&lt;Syck::DefaultKey:0x00000104b82a40&gt; 0.7.2&quot;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
Installing devise <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.4.5<span style="color: #7a0874; font-weight: bold;">&#41;</span> Invalid gemspec <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>.rvm<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>ruby-1.9.2-p180<span style="color: #000000; font-weight: bold;">@</span>cws<span style="color: #000000; font-weight: bold;">/</span>specifications<span style="color: #000000; font-weight: bold;">/</span>cucumber-rails-1.0.4.gemspec<span style="color: #7a0874; font-weight: bold;">&#93;</span>: Illformed requirement <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;#&lt;Syck::DefaultKey:0x00000104b82a40&gt; 0.7.2&quot;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
Installing meta_programming <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.2.2<span style="color: #7a0874; font-weight: bold;">&#41;</span> Invalid gemspec <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>.rvm<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>ruby-1.9.2-p180<span style="color: #000000; font-weight: bold;">@</span>cws<span style="color: #000000; font-weight: bold;">/</span>specifications<span style="color: #000000; font-weight: bold;">/</span>cucumber-rails-1.0.4.gemspec<span style="color: #7a0874; font-weight: bold;">&#93;</span>: Illformed requirement <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;#&lt;Syck::DefaultKey:0x00000104b82a40&gt; 0.7.2&quot;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>

<p>Ok, avoid the PITA moment by reading <a href="https://github.com/cucumber/cucumber/issues/136">this.</a> And make the changes to the Gemfile like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">group <span style="color:#ff3333; font-weight:bold;">:development</span>, <span style="color:#ff3333; font-weight:bold;">:test</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  gem <span style="color:#996600;">'capybara'</span>
  gem <span style="color:#996600;">'cucumber'</span>, <span style="color:#996600;">&quot;1.0.6&quot;</span>
  gem <span style="color:#996600;">'cucumber-rails'</span>, <span style="color:#ff3333; font-weight:bold;">:git</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;https://github.com/cucumber/cucumber-rails.git&quot;</span>
  gem <span style="color:#996600;">'database_cleaner'</span>
  gem <span style="color:#996600;">'rspec-rails'</span>
  gem <span style="color:#996600;">'autotest'</span>
  gem <span style="color:#996600;">'spork'</span>
  gem <span style="color:#996600;">'launchy'</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Now, I understand why the commit message is like this:  <em>I EAT YAML AND RUBYGEMS FOR toot&#8230;</em></p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2011/09/invalid-gemspec-on-what/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails Note #16: rails3, devise, paperclip, uploadify, formtastic</title>
		<link>/wordpress/2011/02/rails-note-16-rails3-devise-paperclip-uploadify-formtastic/</link>
		<comments>/wordpress/2011/02/rails-note-16-rails3-devise-paperclip-uploadify-formtastic/#comments</comments>
		<pubDate>Thu, 10 Feb 2011 09:42:33 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[gallerific]]></category>
		<category><![CDATA[paperclip]]></category>
		<category><![CDATA[rails3]]></category>
		<category><![CDATA[uploadify]]></category>

		<guid isPermaLink="false">/wordpress/?p=823</guid>
		<description><![CDATA[Setup dev:rails3 rupert$ rails new photogallery dev:rails3 rupert$ cd photogallery dev:photogallery rupert$ rm public/index.html dev:photogallery rupert$ vim Gemfile 1 source 'http://rubygems.org' 2 3 gem 'rails', '3.0.3' 4 5 # Bundle edge Rails instead: 6 # gem 'rails', :git =&#62; 'git://github.com/rails/rails.git' 7 8 gem 'sqlite3-ruby', :require =&#62; 'sqlite3' 9 gem 'devise', :git =&#62; &#34;git://github.com/plataformatec/devise.git&#34;, :branch =&#62; [...]]]></description>
			<content:encoded><![CDATA[<h3>Setup</h3>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">dev:rails3 rupert$ rails new photogallery
dev:rails3 rupert$ <span style="color: #7a0874; font-weight: bold;">cd</span> photogallery
dev:photogallery rupert$ <span style="color: #c20cb9; font-weight: bold;">rm</span> public<span style="color: #000000; font-weight: bold;">/</span>index.html</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ vim Gemfile 
  <span style="color:#006666;">1</span> source <span style="color:#996600;">'http://rubygems.org'</span>
  <span style="color:#006666;">2</span> 
  <span style="color:#006666;">3</span> gem <span style="color:#996600;">'rails'</span>, <span style="color:#996600;">'3.0.3'</span>
  <span style="color:#006666;">4</span> 
  <span style="color:#006666;">5</span> <span style="color:#008000; font-style:italic;"># Bundle edge Rails instead:</span>
  <span style="color:#006666;">6</span> <span style="color:#008000; font-style:italic;"># gem 'rails', :git =&gt; 'git://github.com/rails/rails.git'</span>
  <span style="color:#006666;">7</span> 
  <span style="color:#006666;">8</span> gem <span style="color:#996600;">'sqlite3-ruby'</span>, <span style="color:#ff3333; font-weight:bold;">:require</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'sqlite3'</span>
  <span style="color:#006666;">9</span> gem <span style="color:#996600;">'devise'</span>, <span style="color:#ff3333; font-weight:bold;">:git</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;git://github.com/plataformatec/devise.git&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:branch</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;master&quot;</span>
 <span style="color:#006666;">10</span> gem <span style="color:#996600;">'formtastic'</span>, <span style="color:#996600;">'~&gt; 1.1.0'</span>
 <span style="color:#006666;">11</span> gem <span style="color:#996600;">'paperclip'</span>
 <span style="color:#006666;">12</span> gem <span style="color:#996600;">'mime-types'</span>, <span style="color:#ff3333; font-weight:bold;">:require</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'mime/types'</span></pre></div></div>

<p>Paperclip needs imagemagick to work. No need to install by source</p>

<div class="wp_syntax"><div 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;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> imagemagick</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">dev:photogallery rupert$ bundle <span style="color: #c20cb9; font-weight: bold;">install</span>
Updating git:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>plataformatec<span style="color: #000000; font-weight: bold;">/</span>devise.git
Fetching <span style="color: #7a0874; font-weight: bold;">source</span> index <span style="color: #000000; font-weight: bold;">for</span> http:<span style="color: #000000; font-weight: bold;">//</span>rubygems.org<span style="color: #000000; font-weight: bold;">/</span>
Using rake <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.8.7<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using abstract <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.0.0<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using activesupport <span style="color: #7a0874; font-weight: bold;">&#40;</span>3.0.3<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using builder <span style="color: #7a0874; font-weight: bold;">&#40;</span>2.1.2<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using i18n <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.5.0<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using activemodel <span style="color: #7a0874; font-weight: bold;">&#40;</span>3.0.3<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using erubis <span style="color: #7a0874; font-weight: bold;">&#40;</span>2.6.6<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using rack <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.2.1<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using rack-mount <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.6.13<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using rack-test <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.5.7<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using tzinfo <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.3.23<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using actionpack <span style="color: #7a0874; font-weight: bold;">&#40;</span>3.0.3<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using mime-types <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">1.16</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using polyglot <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.3.1<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using treetop <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.4.9<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using mail <span style="color: #7a0874; font-weight: bold;">&#40;</span>2.2.14<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using actionmailer <span style="color: #7a0874; font-weight: bold;">&#40;</span>3.0.3<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using arel <span style="color: #7a0874; font-weight: bold;">&#40;</span>2.0.6<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using activerecord <span style="color: #7a0874; font-weight: bold;">&#40;</span>3.0.3<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using activeresource <span style="color: #7a0874; font-weight: bold;">&#40;</span>3.0.3<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using bcrypt-ruby <span style="color: #7a0874; font-weight: bold;">&#40;</span>2.1.4<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using bundler <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.0.7<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using orm_adapter <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.0.4<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using warden <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.0.3<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using devise <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.2.rc<span style="color: #7a0874; font-weight: bold;">&#41;</span> from git:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>plataformatec<span style="color: #000000; font-weight: bold;">/</span>devise.git <span style="color: #7a0874; font-weight: bold;">&#40;</span>at master<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using formtastic <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.1.0<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using paperclip <span style="color: #7a0874; font-weight: bold;">&#40;</span>2.3.8<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using thor <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.14.6<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using railties <span style="color: #7a0874; font-weight: bold;">&#40;</span>3.0.3<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using rails <span style="color: #7a0874; font-weight: bold;">&#40;</span>3.0.3<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using sqlite3-ruby <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.3.2<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Your bundle is <span style="color: #7a0874; font-weight: bold;">complete</span><span style="color: #000000; font-weight: bold;">!</span> Use <span style="color: #000000; font-weight: bold;">`</span>bundle show <span style="color: #7a0874; font-weight: bold;">&#91;</span>gemname<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #000000; font-weight: bold;">`</span> to see where a bundled gem is installed.</pre></div></div>

<h3>Devise</h3>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ rails g devise:install
      create  config/initializers/devise.rb
      create  config/locales/devise.en.yml
&nbsp;
===============================================================================
&nbsp;
Some setup you must do manually if you haven't yet:
&nbsp;
  1. Setup default url options for your specific environment. Here is an
     example of development environment:
&nbsp;
       config.action_mailer.default_url_options = { :host =&gt; 'localhost:3000' }
&nbsp;
     This is a required Rails configuration. In production it must be the
     actual host of your application
&nbsp;
  2. Ensure you have defined root_url to *something* in your config/routes.rb.
     For example:
&nbsp;
       root :to =&gt; &quot;home#index&quot;
&nbsp;
  3. Ensure you have flash messages in app/views/layouts/application.html.erb.
     For example:
&nbsp;
       &lt;p class=&quot;notice&quot;&gt;<span style="color:#006600; font-weight:bold;">&lt;%</span>= notice <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/p&gt;
       &lt;p class=&quot;alert&quot;&gt;<span style="color:#006600; font-weight:bold;">&lt;%</span>= alert <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/p&gt;
&nbsp;
===============================================================================
dev:photogallery rupert$</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ rails g devise User
      invoke  active_record
      create    app<span style="color:#006600; font-weight:bold;">/</span>models<span style="color:#006600; font-weight:bold;">/</span>user.<span style="color:#9900CC;">rb</span>
      invoke    test_unit
      create      test<span style="color:#006600; font-weight:bold;">/</span>unit<span style="color:#006600; font-weight:bold;">/</span>user_test.<span style="color:#9900CC;">rb</span>
      create      test<span style="color:#006600; font-weight:bold;">/</span>fixtures<span style="color:#006600; font-weight:bold;">/</span>users.<span style="color:#9900CC;">yml</span>
      create    db<span style="color:#006600; font-weight:bold;">/</span>migrate<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006666;">20110210032416</span>_devise_create_users.<span style="color:#9900CC;">rb</span>
      insert    app<span style="color:#006600; font-weight:bold;">/</span>models<span style="color:#006600; font-weight:bold;">/</span>user.<span style="color:#9900CC;">rb</span>
       route  devise_for <span style="color:#ff3333; font-weight:bold;">:users</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#006666;">1</span> <span style="color:#9966CC; font-weight:bold;">class</span> User <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  <span style="color:#006666;">2</span>   <span style="color:#008000; font-style:italic;"># Include default devise modules. Others available are:</span>
  <span style="color:#006666;">3</span>   <span style="color:#008000; font-style:italic;"># :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable</span>
  <span style="color:#006666;">4</span>   devise <span style="color:#ff3333; font-weight:bold;">:database_authenticatable</span>, <span style="color:#ff3333; font-weight:bold;">:registerable</span>,
  <span style="color:#006666;">5</span>          <span style="color:#ff3333; font-weight:bold;">:recoverable</span>, <span style="color:#ff3333; font-weight:bold;">:rememberable</span>, <span style="color:#ff3333; font-weight:bold;">:trackable</span>, <span style="color:#ff3333; font-weight:bold;">:validatable</span>
  <span style="color:#006666;">6</span> 
  <span style="color:#006666;">7</span>   <span style="color:#008000; font-style:italic;"># Setup accessible (or protected) attributes for your model</span>
  <span style="color:#006666;">8</span>   attr_accessible <span style="color:#ff3333; font-weight:bold;">:email</span>, <span style="color:#ff3333; font-weight:bold;">:password</span>, <span style="color:#ff3333; font-weight:bold;">:password_confirmation</span>, <span style="color:#ff3333; font-weight:bold;">:remember_me</span>
  <span style="color:#006666;">9</span> 
 <span style="color:#006666;">10</span>   has_many <span style="color:#ff3333; font-weight:bold;">:pictures</span>
 <span style="color:#006666;">11</span> <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ vim app/controllers/home_controller.rb
  1 class HomeController &lt; ApplicationController
  2   def index
  3   end
  4 end
dev:photogallery rupert$ mkdir -p app/views/home
dev:photogallery rupert$ vim app/views/home/index.html.erb
  1 &lt;h1&gt;Welcome to Photo Gallery&lt;/h1&gt;
  2 <span style="color:#006600; font-weight:bold;">&lt;%</span>= render <span style="color:#ff3333; font-weight:bold;">:partial</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'shared/header'</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
dev:photogallery rupert$ mkdir -p app/views/shared
  1 &lt;ul&gt;
  2   <span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">if</span> user_signed_in? <span style="color:#006600; font-weight:bold;">%&gt;</span>
  3     &lt;li&gt;<span style="color:#006600; font-weight:bold;">&lt;%</span>= link_to <span style="color:#996600;">&quot;Log Out&quot;</span>, destroy_user_session_path <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/li&gt;
  4     &lt;li&gt;<span style="color:#006600; font-weight:bold;">&lt;%</span>= link_to <span style="color:#996600;">&quot;My Pictures&quot;</span>, pictures_path<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:user_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> current_user.<span style="color:#9900CC;">id</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/li&gt;
  5   <span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">else</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  6     &lt;li&gt;<span style="color:#006600; font-weight:bold;">&lt;%</span>= link_to <span style="color:#996600;">&quot;Log In&quot;</span>, new_user_session_path <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/li&gt;
  7     &lt;li&gt;<span style="color:#006600; font-weight:bold;">&lt;%</span>= link_to <span style="color:#996600;">&quot;Sign Up&quot;</span>, new_user_registration_path <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/li&gt;
  8   <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>
  9 &lt;/ul&gt;</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ vim config<span style="color:#006600; font-weight:bold;">/</span>routes.<span style="color:#9900CC;">rb</span>
  <span style="color:#006666;">1</span> <span style="color:#6666ff; font-weight:bold;">Photogallery::Application</span>.<span style="color:#9900CC;">routes</span>.<span style="color:#9900CC;">draw</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#006666;">2</span>   devise_for <span style="color:#ff3333; font-weight:bold;">:users</span>
  <span style="color:#006666;">3</span> 
  <span style="color:#006666;">4</span>   resources <span style="color:#ff3333; font-weight:bold;">:pictures</span>
  <span style="color:#006666;">5</span> 
  <span style="color:#006666;">6</span>   root <span style="color:#ff3333; font-weight:bold;">:to</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;home#index&quot;</span>
  <span style="color:#006666;">7</span> 
  <span style="color:#006666;">8</span> <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<h3>Paperclip</h3>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ vim config<span style="color:#006600; font-weight:bold;">/</span>environments<span style="color:#006600; font-weight:bold;">/</span>development.<span style="color:#9900CC;">rb</span>
  <span style="color:#006666;">1</span> <span style="color:#008000; font-style:italic;"># Be sure to restart your server when you modify this file.</span>
  <span style="color:#006666;">1</span> <span style="color:#6666ff; font-weight:bold;">Photogallery::Application</span>.<span style="color:#9900CC;">configure</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#006666;">2</span>   <span style="color:#008000; font-style:italic;"># Settings specified here will take precedence over those in config/application.rb</span>
  <span style="color:#006666;">3</span> 
  <span style="color:#006666;">4</span>   <span style="color:#008000; font-style:italic;"># In the development environment your application's code is reloaded on</span>
  <span style="color:#006666;">5</span>   <span style="color:#008000; font-style:italic;"># every request.  This slows down response time but is perfect for development</span>
  <span style="color:#006666;">6</span>   <span style="color:#008000; font-style:italic;"># since you don't have to restart the webserver when you make code changes.</span>
  <span style="color:#006666;">7</span>   config.<span style="color:#9900CC;">cache_classes</span> = <span style="color:#0000FF; font-weight:bold;">false</span>
  <span style="color:#006666;">8</span> 
  <span style="color:#006666;">9</span>   <span style="color:#008000; font-style:italic;"># Log error messages when you accidentally call methods on nil.</span>
 <span style="color:#006666;">10</span>   config.<span style="color:#9900CC;">whiny_nils</span> = <span style="color:#0000FF; font-weight:bold;">true</span>
 <span style="color:#006666;">11</span> 
 <span style="color:#006666;">12</span>   <span style="color:#008000; font-style:italic;"># Show full error reports and disable caching</span>
 <span style="color:#006666;">13</span>   config.<span style="color:#9900CC;">consider_all_requests_local</span>       = <span style="color:#0000FF; font-weight:bold;">true</span>
 <span style="color:#006666;">14</span>   config.<span style="color:#9900CC;">action_view</span>.<span style="color:#9900CC;">debug_rjs</span>             = <span style="color:#0000FF; font-weight:bold;">true</span>
 <span style="color:#006666;">15</span>   config.<span style="color:#9900CC;">action_controller</span>.<span style="color:#9900CC;">perform_caching</span> = <span style="color:#0000FF; font-weight:bold;">false</span>
 <span style="color:#006666;">16</span> 
 <span style="color:#006666;">17</span>   <span style="color:#008000; font-style:italic;"># Don't care if the mailer can't send</span>
 <span style="color:#006666;">18</span>   config.<span style="color:#9900CC;">action_mailer</span>.<span style="color:#9900CC;">raise_delivery_errors</span> = <span style="color:#0000FF; font-weight:bold;">false</span>
 <span style="color:#006666;">19</span> 
 <span style="color:#006666;">20</span>   <span style="color:#008000; font-style:italic;"># Print deprecation notices to the Rails logger</span>
 <span style="color:#006666;">21</span>   config.<span style="color:#9900CC;">active_support</span>.<span style="color:#9900CC;">deprecation</span> = <span style="color:#ff3333; font-weight:bold;">:log</span>
 <span style="color:#006666;">22</span> 
 <span style="color:#006666;">23</span>   <span style="color:#008000; font-style:italic;"># Only use best-standards-support built into browsers</span>
 <span style="color:#006666;">24</span>   config.<span style="color:#9900CC;">action_dispatch</span>.<span style="color:#9900CC;">best_standards_support</span> = <span style="color:#ff3333; font-weight:bold;">:builtin</span>
 <span style="color:#006666;">25</span> 
 <span style="color:#006666;">26</span>   Paperclip.<span style="color:#9900CC;">options</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:command_path</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;/usr/local/ImageMagick/bin&quot;</span>
 <span style="color:#006666;">27</span>   Paperclip.<span style="color:#9900CC;">options</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:swallow_stderr</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#0000FF; font-weight:bold;">false</span>
 <span style="color:#006666;">28</span> <span style="color:#9966CC; font-weight:bold;">end</span>
 <span style="color:#006666;">29</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ rails g model Picture
      invoke  active_record
      create    db<span style="color:#006600; font-weight:bold;">/</span>migrate<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006666;">20110210032526</span>_create_pictures.<span style="color:#9900CC;">rb</span>
      create    app<span style="color:#006600; font-weight:bold;">/</span>models<span style="color:#006600; font-weight:bold;">/</span>picture.<span style="color:#9900CC;">rb</span>
      invoke    test_unit
      create      test<span style="color:#006600; font-weight:bold;">/</span>unit<span style="color:#006600; font-weight:bold;">/</span>picture_test.<span style="color:#9900CC;">rb</span>
      create      test<span style="color:#006600; font-weight:bold;">/</span>fixtures<span style="color:#006600; font-weight:bold;">/</span>pictures.<span style="color:#9900CC;">yml</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ vim db<span style="color:#006600; font-weight:bold;">/</span>migrate<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006666;">20110210032526</span>_create_pictures.<span style="color:#9900CC;">rb</span>
  <span style="color:#006666;">1</span> <span style="color:#9966CC; font-weight:bold;">class</span> CreatePictures <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Migration</span>
  <span style="color:#006666;">2</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>
  <span style="color:#006666;">3</span>     create_table <span style="color:#ff3333; font-weight:bold;">:pictures</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>
  <span style="color:#006666;">4</span>       t.<span style="color:#CC0066; font-weight:bold;">string</span> <span style="color:#ff3333; font-weight:bold;">:caption_title</span>
  <span style="color:#006666;">5</span>       t.<span style="color:#9900CC;">text</span> <span style="color:#ff3333; font-weight:bold;">:caption_description</span>
  <span style="color:#006666;">6</span>       
  <span style="color:#006666;">7</span>       t.<span style="color:#9900CC;">references</span> <span style="color:#ff3333; font-weight:bold;">:user</span>
  <span style="color:#006666;">8</span>       
  <span style="color:#006666;">9</span>       t.<span style="color:#9900CC;">timestamps</span>
 <span style="color:#006666;">10</span>     <span style="color:#9966CC; font-weight:bold;">end</span>
 <span style="color:#006666;">11</span>   <span style="color:#9966CC; font-weight:bold;">end</span>
 <span style="color:#006666;">12</span>   
 <span style="color:#006666;">13</span>   <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">down</span>
 <span style="color:#006666;">14</span>     drop_table <span style="color:#ff3333; font-weight:bold;">:pictures</span>
 <span style="color:#006666;">15</span>   <span style="color:#9966CC; font-weight:bold;">end</span>
 <span style="color:#006666;">16</span> <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">dev:photogallery rupert$ rails g migration AddPaperclipToPictures
      invoke  active_record
      create    db<span style="color: #000000; font-weight: bold;">/</span>migrate<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">20110210032654</span>_add_paperclip_to_pictures.rb</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ vim db<span style="color:#006600; font-weight:bold;">/</span>migrate<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006666;">20110210032654</span>_add_paperclip_to_pictures.<span style="color:#9900CC;">rb</span>
  <span style="color:#006666;">1</span> <span style="color:#9966CC; font-weight:bold;">class</span> AddPaperclipToPictures <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Migration</span>
  <span style="color:#006666;">2</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>
  <span style="color:#006666;">3</span>     add_column <span style="color:#ff3333; font-weight:bold;">:pictures</span>, <span style="color:#ff3333; font-weight:bold;">:image_file_name</span>, <span style="color:#ff3333; font-weight:bold;">:string</span>
  <span style="color:#006666;">4</span>     add_column <span style="color:#ff3333; font-weight:bold;">:pictures</span>, <span style="color:#ff3333; font-weight:bold;">:image_content_type</span>, <span style="color:#ff3333; font-weight:bold;">:string</span>
  <span style="color:#006666;">5</span>     add_column <span style="color:#ff3333; font-weight:bold;">:pictures</span>, <span style="color:#ff3333; font-weight:bold;">:image_file_size</span>, <span style="color:#ff3333; font-weight:bold;">:integer</span>
  <span style="color:#006666;">6</span>     add_column <span style="color:#ff3333; font-weight:bold;">:pictures</span>, <span style="color:#ff3333; font-weight:bold;">:image_updated_at</span>, <span style="color:#ff3333; font-weight:bold;">:datetime</span>
  <span style="color:#006666;">7</span>   <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#006666;">8</span> 
  <span style="color:#006666;">9</span>   <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">down</span>
 <span style="color:#006666;">10</span>     remove_column <span style="color:#ff3333; font-weight:bold;">:pictures</span>, <span style="color:#ff3333; font-weight:bold;">:image_file_name</span>
 <span style="color:#006666;">11</span>     remove_column <span style="color:#ff3333; font-weight:bold;">:pictures</span>, <span style="color:#ff3333; font-weight:bold;">:image_content_type</span>
 <span style="color:#006666;">12</span>     remove_column <span style="color:#ff3333; font-weight:bold;">:pictures</span>, <span style="color:#ff3333; font-weight:bold;">:image_file_size</span>
 <span style="color:#006666;">13</span>     remove_column <span style="color:#ff3333; font-weight:bold;">:pictures</span>, <span style="color:#ff3333; font-weight:bold;">:image_updated_at</span>
 <span style="color:#006666;">14</span>   <span style="color:#9966CC; font-weight:bold;">end</span>
 <span style="color:#006666;">15</span> <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ vim app<span style="color:#006600; font-weight:bold;">/</span>models<span style="color:#006600; font-weight:bold;">/</span>picture.<span style="color:#9900CC;">rb</span>
  <span style="color:#006666;">1</span> <span style="color:#9966CC; font-weight:bold;">class</span> Picture <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  <span style="color:#006666;">2</span>   belongs_to <span style="color:#ff3333; font-weight:bold;">:user</span>
  <span style="color:#006666;">3</span> 
  <span style="color:#006666;">4</span>   has_attached_file <span style="color:#ff3333; font-weight:bold;">:image</span>,
  <span style="color:#006666;">5</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:#006666;">6</span>                       <span style="color:#ff3333; font-weight:bold;">:thumb</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;100x100&gt;&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:jpg</span><span style="color:#006600; font-weight:bold;">&#93;</span>,
  <span style="color:#006666;">7</span>                       <span style="color:#ff3333; font-weight:bold;">:pagesize</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;500x400&gt;&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:jpg</span><span style="color:#006600; font-weight:bold;">&#93;</span>,
  <span style="color:#006666;">8</span>                     <span style="color:#006600; font-weight:bold;">&#125;</span>,
  <span style="color:#006666;">9</span>                     <span style="color:#ff3333; font-weight:bold;">:default_style</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:pagesize</span>,
 <span style="color:#006666;">10</span>                     <span style="color:#ff3333; font-weight:bold;">:url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;/images/photogallery/:id/:style/:basename.:extension&quot;</span>,
 <span style="color:#006666;">11</span>                     <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;/wwwroot/images/photogallery/:id/:style/:basename.:extension&quot;</span>
 <span style="color:#006666;">12</span> 
 <span style="color:#006666;">13</span>   validates_attachment_presence <span style="color:#ff3333; font-weight:bold;">:image</span>
 <span style="color:#006666;">14</span>   validates_attachment_size <span style="color:#ff3333; font-weight:bold;">:image</span>, <span style="color:#ff3333; font-weight:bold;">:less_than</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> 10.<span style="color:#9900CC;">megabytes</span>
 <span style="color:#006666;">15</span> <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">dev:images rupert$ <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>wwwroot<span style="color: #000000; font-weight: bold;">/</span>images<span style="color: #000000; font-weight: bold;">/</span>photogallery
dev:images rupert$ <span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>wwwroot<span style="color: #000000; font-weight: bold;">/</span>images<span style="color: #000000; font-weight: bold;">/</span>photogallery photogallery</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ rake db:migrate
<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#9966CC; font-weight:bold;">in</span> <span style="color:#006600; font-weight:bold;">/</span>Volumes<span style="color:#006600; font-weight:bold;">/</span>rupert<span style="color:#006600; font-weight:bold;">/</span>projects<span style="color:#006600; font-weight:bold;">/</span>rails3<span style="color:#006600; font-weight:bold;">/</span>photogallery<span style="color:#006600; font-weight:bold;">&#41;</span>
==  DeviseCreateUsers: migrating ==============================================
<span style="color:#006600; font-weight:bold;">--</span> create_table<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:users</span><span style="color:#006600; font-weight:bold;">&#41;</span>
   <span style="color:#006600; font-weight:bold;">-&gt;</span> 0.0084s
<span style="color:#006600; font-weight:bold;">--</span> add_index<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:users</span>, <span style="color:#ff3333; font-weight:bold;">:email</span>, <span style="color:#006600; font-weight:bold;">&#123;</span>:unique<span style="color:#006600; font-weight:bold;">=&gt;</span>true<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
   <span style="color:#006600; font-weight:bold;">-&gt;</span> 0.0679s
<span style="color:#006600; font-weight:bold;">--</span> add_index<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:users</span>, <span style="color:#ff3333; font-weight:bold;">:reset_password_token</span>, <span style="color:#006600; font-weight:bold;">&#123;</span>:unique<span style="color:#006600; font-weight:bold;">=&gt;</span>true<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
   <span style="color:#006600; font-weight:bold;">-&gt;</span> 0.0007s
==  DeviseCreateUsers: migrated <span style="color:#006600; font-weight:bold;">&#40;</span>0.0772s<span style="color:#006600; font-weight:bold;">&#41;</span> =====================================
&nbsp;
==  CreatePictures: migrating =================================================
<span style="color:#006600; font-weight:bold;">--</span> create_table<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:pictures</span><span style="color:#006600; font-weight:bold;">&#41;</span>
   <span style="color:#006600; font-weight:bold;">-&gt;</span> 0.0007s
==  CreatePictures: migrated <span style="color:#006600; font-weight:bold;">&#40;</span>0.0008s<span style="color:#006600; font-weight:bold;">&#41;</span> ========================================
&nbsp;
==  AddPaperclipToPictures: migrating =========================================
<span style="color:#006600; font-weight:bold;">--</span> add_column<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:pictures</span>, <span style="color:#ff3333; font-weight:bold;">:image_file_name</span>, <span style="color:#ff3333; font-weight:bold;">:string</span><span style="color:#006600; font-weight:bold;">&#41;</span>
   <span style="color:#006600; font-weight:bold;">-&gt;</span> 0.0005s
<span style="color:#006600; font-weight:bold;">--</span> add_column<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:pictures</span>, <span style="color:#ff3333; font-weight:bold;">:image_content_type</span>, <span style="color:#ff3333; font-weight:bold;">:string</span><span style="color:#006600; font-weight:bold;">&#41;</span>
   <span style="color:#006600; font-weight:bold;">-&gt;</span> 0.0003s
<span style="color:#006600; font-weight:bold;">--</span> add_column<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:pictures</span>, <span style="color:#ff3333; font-weight:bold;">:image_file_size</span>, <span style="color:#ff3333; font-weight:bold;">:integer</span><span style="color:#006600; font-weight:bold;">&#41;</span>
   <span style="color:#006600; font-weight:bold;">-&gt;</span> 0.0003s
<span style="color:#006600; font-weight:bold;">--</span> add_column<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:pictures</span>, <span style="color:#ff3333; font-weight:bold;">:image_updated_at</span>, <span style="color:#ff3333; font-weight:bold;">:datetime</span><span style="color:#006600; font-weight:bold;">&#41;</span>
   <span style="color:#006600; font-weight:bold;">-&gt;</span> 0.0003s
==  AddPaperclipToPictures: migrated <span style="color:#006600; font-weight:bold;">&#40;</span>0.0016s<span style="color:#006600; font-weight:bold;">&#41;</span> ================================</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">dev:photogallery rupert$ rails g controller pictures
      create  app<span style="color: #000000; font-weight: bold;">/</span>controllers<span style="color: #000000; font-weight: bold;">/</span>pictures_controller.rb
      invoke  erb
      create    app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>pictures
      invoke  helper
      create    app<span style="color: #000000; font-weight: bold;">/</span>helpers<span style="color: #000000; font-weight: bold;">/</span>pictures_helper.rb</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ vim app<span style="color:#006600; font-weight:bold;">/</span>controllers<span style="color:#006600; font-weight:bold;">/</span>pictures_controller.<span style="color:#9900CC;">rb</span> 
  <span style="color:#006666;">1</span> <span style="color:#9966CC; font-weight:bold;">class</span> PicturesController <span style="color:#006600; font-weight:bold;">&lt;</span> ApplicationController
  <span style="color:#006666;">2</span>   <span style="color:#9966CC; font-weight:bold;">def</span> index
  <span style="color:#006666;">3</span>     <span style="color:#0066ff; font-weight:bold;">@user</span> = User.<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;">:user_id</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#006666;">4</span>     <span style="color:#0066ff; font-weight:bold;">@pictures</span> = <span style="color:#0066ff; font-weight:bold;">@user</span>.<span style="color:#9900CC;">pictures</span>
  <span style="color:#006666;">5</span>   <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#006666;">6</span> 
  <span style="color:#006666;">7</span>   <span style="color:#9966CC; font-weight:bold;">def</span> create
  <span style="color:#006666;">8</span>     <span style="color:#008000; font-style:italic;">#You can specify a sleep here to mimic a long response</span>
  <span style="color:#006666;">9</span>     <span style="color:#008000; font-style:italic;">#sleep 5</span>
 <span style="color:#006666;">10</span>     newparams = coerce<span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#41;</span>
 <span style="color:#006666;">11</span> 
 <span style="color:#006666;">12</span>     current_pictures = Picture.<span style="color:#9900CC;">where</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:user_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:user_id</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">all</span>
 <span style="color:#006666;">13</span> 
 <span style="color:#006666;">14</span>     <span style="color:#0066ff; font-weight:bold;">@picture</span> = Picture.<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;">:picture</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
 <span style="color:#006666;">15</span>     <span style="color:#0066ff; font-weight:bold;">@picture</span>.<span style="color:#9900CC;">user_id</span> = current_user.<span style="color:#9900CC;">id</span>
 <span style="color:#006666;">16</span> 
 <span style="color:#006666;">17</span>     <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@picture</span>.<span style="color:#9900CC;">save</span>
 <span style="color:#006666;">18</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;Picture was successfully created&quot;</span>
 <span style="color:#006666;">19</span> 
 <span style="color:#006666;">20</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:#006666;">21</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 pictures_path<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:user_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@picture</span>.<span style="color:#9900CC;">user_id</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
 <span style="color:#006666;">22</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;">:picture</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> picture_path<span style="color:#006600; font-weight:bold;">&#40;</span>@picture<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:#006666;">23</span>       <span style="color:#9966CC; font-weight:bold;">end</span>
 <span style="color:#006666;">24</span>     <span style="color:#9966CC; font-weight:bold;">else</span>
 <span style="color:#006666;">25</span>       flash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:alert</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;There is an error in saving the picture.&quot;</span>
 <span style="color:#006666;">26</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:#006666;">27</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 pictures_path<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:user_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@picture</span>.<span style="color:#9900CC;">user_id</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
 <span style="color:#006666;">28</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;">'error'</span>, <span style="color:#ff3333; font-weight:bold;">:error</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> flash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:alert</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
 <span style="color:#006666;">29</span>       <span style="color:#9966CC; font-weight:bold;">end</span>
 <span style="color:#006666;">30</span>     <span style="color:#9966CC; font-weight:bold;">end</span>
 <span style="color:#006666;">31</span>   <span style="color:#9966CC; font-weight:bold;">end</span>
 <span style="color:#006666;">32</span>   
 <span style="color:#006666;">33</span>   <span style="color:#9966CC; font-weight:bold;">def</span> show
 <span style="color:#006666;">34</span>     <span style="color:#0066ff; font-weight:bold;">@picture</span> = Picture.<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:#ff3333; font-weight:bold;">:include</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:user</span><span style="color:#006600; font-weight:bold;">&#41;</span>
 <span style="color:#006666;">35</span>     <span style="color:#0066ff; font-weight:bold;">@total_pictures</span> = Picture.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:all</span>, <span style="color:#ff3333; font-weight:bold;">:conditions</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;">:user_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@picture</span>.<span style="color:#9900CC;">user</span>.<span style="color:#9900CC;">id</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
 <span style="color:#006666;">36</span>     render <span style="color:#ff3333; font-weight:bold;">:template</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'pictures/show'</span>
 <span style="color:#006666;">37</span>   <span style="color:#9966CC; font-weight:bold;">end</span>
 <span style="color:#006666;">38</span>   
 <span style="color:#006666;">39</span>   <span style="color:#9966CC; font-weight:bold;">def</span> destroy
 <span style="color:#006666;">40</span>     picture = Picture.<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:#006666;">41</span>     user_id = picture.<span style="color:#9900CC;">user_id</span>
 <span style="color:#006666;">42</span>     picture.<span style="color:#9900CC;">destroy</span>
 <span style="color:#006666;">43</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;Picture was successfully deleted&quot;</span>
 <span style="color:#006666;">44</span>     redirect_to pictures_path<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:user_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> user_id<span style="color:#006600; font-weight:bold;">&#41;</span>
 <span style="color:#006666;">45</span>   <span style="color:#9966CC; font-weight:bold;">end</span>
 <span style="color:#006666;">46</span>     
 <span style="color:#006666;">47</span>   private
 <span style="color:#006666;">48</span>     <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:#006666;">49</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;">:picture</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#0000FF; font-weight:bold;">nil</span>?
 <span style="color:#006666;">50</span>         h = <span style="color:#CC00FF; font-weight:bold;">Hash</span>.<span style="color:#9900CC;">new</span> 
 <span style="color:#006666;">51</span>         h<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:picture</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>
 <span style="color:#006666;">52</span>         h<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:picture</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;">:user_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;">:user_id</span><span style="color:#006600; font-weight:bold;">&#93;</span>
 <span style="color:#006666;">53</span>         h<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:picture</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;">:image</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>
 <span style="color:#006666;">54</span>         h<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:picture</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;">:image</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;">:picture</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;">:image</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>
 <span style="color:#006666;">55</span>         h
 <span style="color:#006666;">56</span>       <span style="color:#9966CC; font-weight:bold;">else</span>
 <span style="color:#006666;">57</span>         params
 <span style="color:#006666;">58</span>       <span style="color:#9966CC; font-weight:bold;">end</span> 
 <span style="color:#006666;">59</span>     <span style="color:#9966CC; font-weight:bold;">end</span>
 <span style="color:#006666;">60</span> <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<h3>Uploadify</h3>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ vim config<span style="color:#006600; font-weight:bold;">/</span>initializers<span style="color:#006600; font-weight:bold;">/</span>session_store.<span style="color:#9900CC;">rb</span>
  <span style="color:#006666;">1</span> <span style="color:#008000; font-style:italic;"># Be sure to restart your server when you modify this file.</span>
  <span style="color:#006666;">2</span> 
  <span style="color:#006666;">3</span> <span style="color:#6666ff; font-weight:bold;">Photogallery::Application</span>.<span style="color:#9900CC;">config</span>.<span style="color:#9900CC;">session_store</span> <span style="color:#ff3333; font-weight:bold;">:cookie_store</span>, <span style="color:#ff3333; font-weight:bold;">:key</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'_photogallery_session'</span>
  <span style="color:#006666;">4</span> 
  <span style="color:#006666;">5</span> <span style="color:#008000; font-style:italic;"># Use the database for sessions instead of the cookie-based default,</span>
  <span style="color:#006666;">6</span> <span style="color:#008000; font-style:italic;"># which shouldn't be used to store highly confidential information</span>
  <span style="color:#006666;">7</span> <span style="color:#008000; font-style:italic;"># (create the session table with &quot;rails generate session_migration&quot;)</span>
  <span style="color:#006666;">8</span> <span style="color:#008000; font-style:italic;"># Photogallery::Application.config.session_store :active_record_store</span>
  <span style="color:#006666;">9</span> Rails.<span style="color:#9900CC;">application</span>.<span style="color:#9900CC;">config</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:#006666;">10</span>   <span style="color:#6666ff; font-weight:bold;">ActionDispatch::Session::CookieStore</span>,
 <span style="color:#006666;">11</span>   FlashSessionCookieMiddleware,
 <span style="color:#006666;">12</span>   Rails.<span style="color:#9900CC;">application</span>.<span style="color:#9900CC;">config</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:#006666;">13</span> <span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ mkdir app<span style="color:#006600; font-weight:bold;">/</span>middleware
dev:photogallery rupert$ vim app<span style="color:#006600; font-weight:bold;">/</span>middleware<span style="color:#006600; font-weight:bold;">/</span>flash_session_cookie_middleware.<span style="color:#9900CC;">rb</span>
  <span style="color:#006666;">1</span> <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rack/utils'</span>
  <span style="color:#006666;">2</span>  
  <span style="color:#006666;">3</span> <span style="color:#9966CC; font-weight:bold;">class</span> FlashSessionCookieMiddleware
  <span style="color:#006666;">4</span>   <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:#006666;">5</span>     <span style="color:#0066ff; font-weight:bold;">@app</span> = app
  <span style="color:#006666;">6</span>     <span style="color:#0066ff; font-weight:bold;">@session_key</span> = session_key
  <span style="color:#006666;">7</span>   <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#006666;">8</span>  
  <span style="color:#006666;">9</span>   <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:#006666;">10</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>
 <span style="color:#006666;">11</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>
 <span style="color:#006666;">12</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:#006600; font-weight:bold;">&#91;</span> <span style="color:#0066ff; font-weight:bold;">@session_key</span>,
 <span style="color:#006666;">13</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:#006600; font-weight:bold;">&#93;</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>.<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:#006666;">14</span>       env<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'HTTP_ACCEPT'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;#{req.params['_http_accept']}&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><span style="color:#996600;">'_http_accept'</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#0000FF; font-weight:bold;">nil</span>?
 <span style="color:#006666;">15</span>     <span style="color:#9966CC; font-weight:bold;">end</span>
 <span style="color:#006666;">16</span>  
 <span style="color:#006666;">17</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:#006666;">18</span>   <span style="color:#9966CC; font-weight:bold;">end</span>
 <span style="color:#006666;">19</span> <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">dev:photogallery rupert$ <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> public<span style="color: #000000; font-weight: bold;">/</span>javascripts<span style="color: #000000; font-weight: bold;">/*</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">dev:photogallery rupert$ <span style="color: #7a0874; font-weight: bold;">cd</span> doc<span style="color: #000000; font-weight: bold;">/</span>
dev:doc rupert$ <span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.uploadify.com<span style="color: #000000; font-weight: bold;">/</span>wp-content<span style="color: #000000; font-weight: bold;">/</span>uploads<span style="color: #000000; font-weight: bold;">/</span>Uploadify-v2.1.4.zip
<span style="color: #660033;">--<span style="color: #000000;">2011</span>-02-10</span> <span style="color: #000000;">14</span>:<span style="color: #000000;">58</span>:<span style="color: #000000;">26</span>--  http:<span style="color: #000000; font-weight: bold;">//</span>www.uploadify.com<span style="color: #000000; font-weight: bold;">/</span>wp-content<span style="color: #000000; font-weight: bold;">/</span>uploads<span style="color: #000000; font-weight: bold;">/</span>Uploadify-v2.1.4.zip
Resolving www.uploadify.com... 67.205.57.45
Connecting to www.uploadify.com<span style="color: #000000; font-weight: bold;">|</span>67.205.57.45<span style="color: #000000; font-weight: bold;">|</span>:80... connected.
HTTP request sent, awaiting response... <span style="color: #000000;">200</span> OK
Length: <span style="color: #000000;">237327</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>232K<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>application<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">zip</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
Saving to: <span style="color: #000000; font-weight: bold;">`</span>Uploadify-v2.1.4.zip<span style="color: #ff0000;">'
&nbsp;
100%[===========================================================================================================================================&gt;] 237,327     88.9K/s   in 2.6s    
&nbsp;
2011-02-10 14:58:29 (88.9 KB/s) - `Uploadify-v2.1.4.zip'</span> saved <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">237327</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">237327</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
dev:doc rupert$ <span style="color: #c20cb9; font-weight: bold;">unzip</span> Uploadify-v2.1.4.zip
dev:doc rupert$ <span style="color: #7a0874; font-weight: bold;">cd</span> jquery.uploadify-v2.1.4<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;
dev:jquery.uploadify-v2.1.4 rupert$ <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> ..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>public<span style="color: #000000; font-weight: bold;">/</span>javascripts<span style="color: #000000; font-weight: bold;">/</span>uploadify
dev:jquery.uploadify-v2.1.4 rupert$ <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> ..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>public<span style="color: #000000; font-weight: bold;">/</span>uploadify
&nbsp;
dev:jquery.uploadify-v2.1.4 rupert$ <span style="color: #c20cb9; font-weight: bold;">cp</span> uploadify.css ..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>public<span style="color: #000000; font-weight: bold;">/</span>stylesheets<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;
dev:jquery.uploadify-v2.1.4 rupert$ <span style="color: #c20cb9; font-weight: bold;">cp</span> jquery.uploadify.v2.1.4.js ..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>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>
dev:jquery.uploadify-v2.1.4 rupert$ <span style="color: #c20cb9; font-weight: bold;">cp</span> swfobject.js ..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>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>
&nbsp;
dev:jquery.uploadify-v2.1.4 rupert$ <span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #660033;">-Rf</span> uploadify.swf ..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>public<span style="color: #000000; font-weight: bold;">/</span>uploadify<span style="color: #000000; font-weight: bold;">/</span>
dev:jquery.uploadify-v2.1.4 rupert$ <span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #660033;">-Rf</span> cancel.png ..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>public<span style="color: #000000; font-weight: bold;">/</span>uploadify<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;
dev:photogallery rupert$ <span style="color: #7a0874; font-weight: bold;">cd</span> ..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>public<span style="color: #000000; font-weight: bold;">/</span>javascripts<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">wget</span> https:<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>jquery-ujs<span style="color: #000000; font-weight: bold;">/</span>raw<span style="color: #000000; font-weight: bold;">/</span>master<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>rails.js <span style="color: #660033;">--no-check-certificate</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ vim app/views/layouts/pictures.html.erb
  1 &lt;!DOCTYPE html&gt;
  2 &lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;en&quot; lang=&quot;en&quot;&gt;
  3 &lt;head&gt;
  4   &lt;title&gt;Photo Gallery&lt;/title&gt;
  5   
  6   <span style="color:#006600; font-weight:bold;">&lt;%</span>= stylesheet_link_tag <span style="color:#996600;">'formtastic/formtastic'</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  7   <span style="color:#006600; font-weight:bold;">&lt;%</span>= stylesheet_link_tag <span style="color:#996600;">'formtastic/formtastic_changes'</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  8 
  9   <span style="color:#006600; font-weight:bold;">&lt;%</span>= stylesheet_link_tag <span style="color:#996600;">'uploadify'</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 10 
 11   <span style="color:#006600; font-weight:bold;">&lt;%</span>= javascript_include_tag <span style="color:#996600;">'https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js'</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 12   
 13   &lt;!-- 
 14     Taken from https://github.com/rails/jquery-ujs/raw/master/src/rails.js
 15     Do not remove jquery.rails.js as the delete links will not work 
 16   --&gt;
 17   <span style="color:#006600; font-weight:bold;">&lt;%</span>= javascript_include_tag <span style="color:#996600;">&quot;jquery.rails.js&quot;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 18   
 19   <span style="color:#006600; font-weight:bold;">&lt;%</span>= csrf_meta_tag <span style="color:#006600; font-weight:bold;">%&gt;</span>
 20 &lt;/head&gt;
 21 &lt;body&gt;
 22 &lt;div class=&quot;container&quot;&gt;
 23   <span style="color:#006600; font-weight:bold;">&lt;%</span> flash.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>name, msg<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 24     &lt;hr/&gt;
 25     <span style="color:#006600; font-weight:bold;">&lt;%</span>= content_tag <span style="color:#ff3333; font-weight:bold;">:div</span>, msg, <span style="color:#ff3333; font-weight:bold;">:class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;flash_#{name}&quot;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 26   <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>
 27 
 28   <span style="color:#006600; font-weight:bold;">&lt;%</span>= render <span style="color:#ff3333; font-weight:bold;">:partial</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'shared/header'</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 29 
 30   &lt;hr/&gt;
 31 
 32   <span style="color:#006600; font-weight:bold;">&lt;%</span>= <span style="color:#9966CC; font-weight:bold;">yield</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 33 
 34 &lt;/div&gt;
 35 
 36 &lt;/body&gt;
 37 &lt;/html&gt;</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ vim app/views/pictures/index.html.erb
  1 &lt;h1&gt;<span style="color:#006600; font-weight:bold;">&lt;%</span>= <span style="color:#996600;">&quot;Manage #{pluralize(@user.pictures.size, 'Picture')}&quot;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/h1&gt;
  2 
  3   &lt;div class=&quot;upload_form&quot;&gt;
  4     <span style="color:#006600; font-weight:bold;">&lt;%</span>= form_for Picture.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:user_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@user</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>:multipart <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>
  5       &lt;h2&gt;Step 1: Choose your images&lt;/h2&gt;
  6       <span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">file_field</span> <span style="color:#ff3333; font-weight:bold;">:image</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  7 
  8       <span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">hidden_field</span> <span style="color:#ff3333; font-weight:bold;">:user_id</span>, <span style="color:#996600;">&quot;value&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@user</span>.<span style="color:#9900CC;">id</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  9 
 10       &lt;h2&gt;Step 2: Upload&lt;/h2&gt;
 11       <span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">submit</span> <span style="color:#996600;">'Upload'</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 12     <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>
 13 
 14     <span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">if</span> simple_upload_form? <span style="color:#006600; font-weight:bold;">%&gt;</span>
 15 
 16       &lt;span class=&quot;simple_upload_link&quot;&gt;
 17         If you want to see the Browse flash button above, click on the
 18         <span style="color:#006600; font-weight:bold;">&lt;%</span>= link_to <span style="color:#996600;">&quot;Flash Upload&quot;</span>, pictures_path<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:user_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@user</span>.<span style="color:#9900CC;">id</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 19       &lt;/span&gt;
 20 
 21     <span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">else</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 22 
 23       &lt;!-- Important: Please see uploadify. It contains javascript functions to provide the BROWSE button, submit to a user with content_type json, and process the response. See     more details in uploadify --&gt;
 24       <span style="color:#006600; font-weight:bold;">&lt;%</span>= render <span style="color:#ff3333; font-weight:bold;">:partial</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;uploadify&quot;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 25 
 26       &lt;span class=&quot;simple_upload_link&quot;&gt;
 27         If you cannot see the Browse flash button above, click on the
 28         <span style="color:#006600; font-weight:bold;">&lt;%</span>= link_to <span style="color:#996600;">&quot;Simple Upload&quot;</span>, pictures_path<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:user_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@user</span>.<span style="color:#9900CC;">id</span>, <span style="color:#ff3333; font-weight:bold;">:simple</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 29       &lt;/span&gt;
 30 
 31     <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>
 32   &lt;/div&gt;
 33 
 34 &lt;div class=&quot;clear&quot;&gt;&lt;/div&gt;
 35 
 36 &lt;hr/&gt;
 37 
 38 &lt;div class=&quot;picture_container&quot;&gt;
 39   &lt;ul class=&quot;thumbs noscript&quot;&gt;
 40     <span style="color:#006600; font-weight:bold;">&lt;%</span>= render <span style="color:#0066ff; font-weight:bold;">@pictures</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 41   &lt;/ul&gt;
 42 &lt;/div&gt;</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">dev<span style="color: #339933;">:</span>photogallery rupert$ vim app<span style="color: #339933;">/</span>views<span style="color: #339933;">/</span>pictures<span style="color: #339933;">/</span>_uploadify.<span style="color: #660066;">html</span>.<span style="color: #660066;">erb</span> 
  <span style="color: #CC0000;">1</span> <span style="color: #339933;">&lt;%=</span> javascript_include_tag <span style="color: #3366CC;">&quot;uploadify/swfobject.js&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;uploadify/jquery.uploadify.v2.1.4.js&quot;</span> <span style="color: #339933;">%&gt;</span>
  <span style="color: #CC0000;">2</span> 
  <span style="color: #CC0000;">3</span> <span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span> charset<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;utf-8&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #CC0000;">4</span> <span style="color: #339933;">&lt;%-</span> session_key <span style="color: #339933;">=</span> Rails.<span style="color: #660066;">application</span>.<span style="color: #660066;">config</span>.<span style="color: #660066;">session_options</span><span style="color: #009900;">&#91;</span><span style="color: #339933;">:</span>key<span style="color: #009900;">&#93;</span> <span style="color: #339933;">-%&gt;</span> 
  <span style="color: #CC0000;">5</span> $<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #CC0000;">6</span>   
  <span style="color: #CC0000;">7</span>   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#picture_image'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> 
  <span style="color: #CC0000;">8</span>     event.<span style="color: #660066;">preventDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #CC0000;">9</span>   <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
 <span style="color: #CC0000;">10</span>   
 <span style="color: #CC0000;">11</span>   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#picture_image'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">uploadify</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
 <span style="color: #CC0000;">12</span>     buttonText<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Browse'</span><span style="color: #339933;">,</span>
 <span style="color: #CC0000;">13</span>     width<span style="color: #339933;">:</span> <span style="color: #CC0000;">110</span><span style="color: #339933;">,</span>
 <span style="color: #CC0000;">14</span>     uploader <span style="color: #339933;">:</span> <span style="color: #3366CC;">'/images/uploadify/uploadify.swf'</span><span style="color: #339933;">,</span>
 <span style="color: #CC0000;">15</span>     cancelImg <span style="color: #339933;">:</span> <span style="color: #3366CC;">'/images/uploadify/cancel.png'</span><span style="color: #339933;">,</span>
 <span style="color: #CC0000;">16</span>     multi <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
 <span style="color: #CC0000;">17</span>     auto <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
 <span style="color: #CC0000;">18</span>     script <span style="color: #339933;">:</span> <span style="color: #3366CC;">'pictures'</span><span style="color: #339933;">,</span>
 <span style="color: #CC0000;">19</span>     <span style="color: #006600; font-style: italic;">//Function 'onComplete' below will process response from pictures_controller 'create'</span>
 <span style="color: #CC0000;">20</span>     <span style="color: #006600; font-style: italic;">//format.json {render :json =&gt; { :result =&gt; 'success', :picture =&gt; admin_picture_path(@picture) } }</span>
 <span style="color: #CC0000;">21</span>     onComplete <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #339933;">,</span> queueID<span style="color: #339933;">,</span> fileObj<span style="color: #339933;">,</span> response<span style="color: #339933;">,</span> data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
 <span style="color: #CC0000;">22</span>       <span style="color: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">eval</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'('</span> <span style="color: #339933;">+</span> response <span style="color: #339933;">+</span> <span style="color: #3366CC;">')'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #CC0000;">23</span>       <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">result</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'success'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
 <span style="color: #CC0000;">24</span>         $.<span style="color: #660066;">getScript</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">picture</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #CC0000;">25</span>       <span style="color: #009900;">&#125;</span>
 <span style="color: #CC0000;">26</span>       <span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
 <span style="color: #CC0000;">27</span>         <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">error</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #CC0000;">28</span>         <span style="color: #006600; font-style: italic;">//We can have a &lt;hr/&gt; before alert or notice using jquery</span>
 <span style="color: #CC0000;">29</span>         $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#alert'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">error</span><span style="color: #009900;">&#41;</span>
 <span style="color: #CC0000;">30</span>       <span style="color: #009900;">&#125;</span>
 <span style="color: #CC0000;">31</span>     <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
 <span style="color: #CC0000;">32</span>     scriptData <span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #CC0000;">33</span>           <span style="color: #3366CC;">'_http_accept'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'application/javascript'</span><span style="color: #339933;">,</span>
 <span style="color: #CC0000;">34</span>           <span style="color: #3366CC;">'format'</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">'json'</span><span style="color: #339933;">,</span>
 <span style="color: #CC0000;">35</span>           <span style="color: #3366CC;">'_method'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'post'</span><span style="color: #339933;">,</span>
 <span style="color: #CC0000;">36</span>           <span style="color: #3366CC;">'&lt;%= session_key %&gt;'</span> <span style="color: #339933;">:</span> encodeURIComponent<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;%= u cookies[session_key] %&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
 <span style="color: #CC0000;">37</span>           <span style="color: #3366CC;">'authenticity_token'</span><span style="color: #339933;">:</span> encodeURIComponent<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;%= u form_authenticity_token %&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
 <span style="color: #CC0000;">38</span>           <span style="color: #3366CC;">'user_id'</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">'&lt;%= @user.id %&gt;'</span>
 <span style="color: #CC0000;">39</span>         <span style="color: #009900;">&#125;</span>
 <span style="color: #CC0000;">40</span>   <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #CC0000;">41</span>   
 <span style="color: #CC0000;">42</span>   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#picture_submit'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> 
 <span style="color: #CC0000;">43</span>       event.<span style="color: #660066;">preventDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
 <span style="color: #CC0000;">44</span>       $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#upload_photo'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">uploadifyUpload</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
 <span style="color: #CC0000;">45</span>     <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #CC0000;">46</span>     
 <span style="color: #CC0000;">47</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
 <span style="color: #CC0000;">48</span> <span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ vim app<span style="color:#006600; font-weight:bold;">/</span>helpers<span style="color:#006600; font-weight:bold;">/</span>pictures_helper.<span style="color:#9900CC;">rb</span>
  <span style="color:#006666;">1</span> <span style="color:#9966CC; font-weight:bold;">module</span> PicturesHelper
  <span style="color:#006666;">2</span>   <span style="color:#9966CC; font-weight:bold;">def</span> simple_upload_form?
  <span style="color:#006666;">3</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;">:simple</span><span style="color:#006600; font-weight:bold;">&#93;</span> == <span style="color:#0000FF; font-weight:bold;">nil</span>
  <span style="color:#006666;">4</span>       <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0000FF; font-weight:bold;">false</span>
  <span style="color:#006666;">5</span>     <span style="color:#9966CC; font-weight:bold;">else</span>
  <span style="color:#006666;">6</span>       <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0000FF; font-weight:bold;">true</span>
  <span style="color:#006666;">7</span>     <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#006666;">8</span>   <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#006666;">9</span> 
 <span style="color:#006666;">10</span>   <span style="color:#9966CC; font-weight:bold;">def</span> link_to_picture<span style="color:#006600; font-weight:bold;">&#40;</span>picture<span style="color:#006600; font-weight:bold;">&#41;</span>
 <span style="color:#006666;">11</span>     link_to<span style="color:#006600; font-weight:bold;">&#40;</span>
 <span style="color:#006666;">12</span>       image_tag<span style="color:#006600; font-weight:bold;">&#40;</span> picture.<span style="color:#9900CC;">image</span>.<span style="color:#9900CC;">url</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:thumb</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#ff3333; font-weight:bold;">:size</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'80x80'</span>, <span style="color:#ff3333; font-weight:bold;">:border</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:#006666;">13</span>       picture.<span style="color:#9900CC;">image</span>.<span style="color:#9900CC;">url</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:pagesize</span><span style="color:#006600; font-weight:bold;">&#41;</span>,
 <span style="color:#006666;">14</span>       <span style="color:#006600; font-weight:bold;">&#123;</span>
 <span style="color:#006666;">15</span>         <span style="color:#ff3333; font-weight:bold;">:class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;thumb&quot;</span>,
 <span style="color:#006666;">16</span>         <span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;#{picture.image_file_name}&quot;</span>,
 <span style="color:#006666;">17</span>         <span style="color:#ff3333; font-weight:bold;">:name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;#{picture.image_file_name}&quot;</span>,
 <span style="color:#006666;">18</span>         <span style="color:#ff3333; font-weight:bold;">:rel</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;nofollow&quot;</span>
 <span style="color:#006666;">19</span>       <span style="color:#006600; font-weight:bold;">&#125;</span>
 <span style="color:#006666;">20</span>     <span style="color:#006600; font-weight:bold;">&#41;</span>
 <span style="color:#006666;">21</span>   <span style="color:#9966CC; font-weight:bold;">end</span>
 <span style="color:#006666;">22</span> 
 <span style="color:#006666;">23</span>   <span style="color:#9966CC; font-weight:bold;">def</span> link_to_web_photo<span style="color:#006600; font-weight:bold;">&#40;</span>photo<span style="color:#006600; font-weight:bold;">&#41;</span>
 <span style="color:#006666;">24</span>     link_to<span style="color:#006600; font-weight:bold;">&#40;</span>
 <span style="color:#006666;">25</span>       image_tag<span style="color:#006600; font-weight:bold;">&#40;</span> photo.<span style="color:#9900CC;">thumb_path</span>, <span style="color:#ff3333; font-weight:bold;">:size</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'80x80'</span>, <span style="color:#ff3333; font-weight:bold;">:border</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:#006666;">26</span>       photo.<span style="color:#9900CC;">full_path</span>,
 <span style="color:#006666;">27</span>       <span style="color:#006600; font-weight:bold;">&#123;</span>
 <span style="color:#006666;">28</span>         <span style="color:#ff3333; font-weight:bold;">:class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;thumb&quot;</span>,
 <span style="color:#006666;">29</span>         <span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;#{photo.thumb_path}&quot;</span>,
 <span style="color:#006666;">30</span>         <span style="color:#ff3333; font-weight:bold;">:name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;#{photo.thumb_path}&quot;</span>,
 <span style="color:#006666;">31</span>         <span style="color:#ff3333; font-weight:bold;">:rel</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;nofollow&quot;</span>
 <span style="color:#006666;">32</span>       <span style="color:#006600; font-weight:bold;">&#125;</span>
 <span style="color:#006666;">33</span>     <span style="color:#006600; font-weight:bold;">&#41;</span>
 <span style="color:#006666;">34</span>   <span style="color:#9966CC; font-weight:bold;">end</span>
 <span style="color:#006666;">35</span> <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ vim app/views/pictures/_picture.html.erb
  1 &lt;li&gt;
  2   &lt;p&gt;
  3     <span style="color:#006600; font-weight:bold;">&lt;%</span>= link_to_picture<span style="color:#006600; font-weight:bold;">&#40;</span>picture<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;br/&gt;
  4     <span style="color:#006600; font-weight:bold;">&lt;%</span>= picture.<span style="color:#9900CC;">caption_title</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  5   &lt;/p&gt;
  6   <span style="color:#006600; font-weight:bold;">&lt;%</span>= link_to <span style="color:#996600;">&quot;Delete Picture&quot;</span>, picture_path<span style="color:#006600; font-weight:bold;">&#40;</span>picture<span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#ff3333; font-weight:bold;">:confirm</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;Are you sure?&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:method</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:delete</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  7 &lt;/li&gt;</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ vim app/views/pictures/show.js.erb
  1 $('h1').html('Manage <span style="color:#006600; font-weight:bold;">&lt;%</span>= pluralize<span style="color:#006600; font-weight:bold;">&#40;</span>@total_pictures.<span style="color:#9900CC;">count</span>, <span style="color:#996600;">&quot;Picture&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>');
  2 $('ul.thumbs').append('<span style="color:#006600; font-weight:bold;">&lt;%</span>= escape_javascript<span style="color:#006600; font-weight:bold;">&#40;</span>render <span style="color:#0066ff; font-weight:bold;">@picture</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>');</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ vim app/views/pictures/edit.html.erb
  1 <span style="color:#006600; font-weight:bold;">&lt;%</span> title <span style="color:#996600;">'Edit Caption'</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  2 
  3 <span style="color:#006600; font-weight:bold;">&lt;%</span>= render <span style="color:#996600;">&quot;shared/error_messages&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:target</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@picture</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  4 
  5 &lt;p style=&quot;text-align:center&quot;&gt;<span style="color:#006600; font-weight:bold;">&lt;%</span>= image_tag <span style="color:#0066ff; font-weight:bold;">@picture</span>.<span style="color:#9900CC;">image</span>.<span style="color:#9900CC;">url</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:pagesize</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/p&gt;
  6 
  7 <span style="color:#006600; font-weight:bold;">&lt;%</span>= semantic_form_for <span style="color:#0066ff; font-weight:bold;">@picture</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>
  8   <span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">inputs</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  9     <span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">input</span> <span style="color:#ff3333; font-weight:bold;">:caption_title</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 10     <span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">input</span> <span style="color:#ff3333; font-weight:bold;">:caption_description</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 11   <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>
 12   
 13   <span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">buttons</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 14     <span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">commit_button</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 15     <span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">cancel_button</span> pictures_path<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:page_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@picture</span>.<span style="color:#9900CC;">page</span>.<span style="color:#9900CC;">id</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 16   <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>
 17   
 18 <span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></div></div>

<p>Download <a href="/wordpress/wp-content/uploads/2011/02/photogallery.tar1.gz" title="photogallery.tar.gz">photogallery.tar.gz</a></p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2011/02/rails-note-16-rails3-devise-paperclip-uploadify-formtastic/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails Note #9: Getting HTTP Headers</title>
		<link>/wordpress/2008/11/rubyonrails-getting-http-headers/</link>
		<comments>/wordpress/2008/11/rubyonrails-getting-http-headers/#comments</comments>
		<pubDate>Thu, 20 Nov 2008 12:49:32 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">/wordpress/?p=298</guid>
		<description><![CDATA[1. I was trying to get the http headers dump from a mobile phone. So I quickly dump it in a log file to see its contents.. headers&#91;'Content-Type'&#93; = 'text/xml; charset=utf-8' for header in request.env.select &#123;&#124;k,v&#124; k.match&#40;&#34;^HTTP.*&#34;&#41;&#125; logger.info&#40;header&#91;0&#93;.split&#40;'_',2&#41;&#91;1&#93; + &#34;:&#34; + header&#91;1&#93;&#41; end Reference: http://tonycode.com/wiki/index.php?title=Dumping_HTTP_Headers 2. However, please note that you can actually see everything [...]]]></description>
			<content:encoded><![CDATA[<p>1. I was trying to get the http headers dump from a mobile phone. So I quickly dump it in a log file to see its contents..</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">    headers<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'Content-Type'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">'text/xml; charset=utf-8'</span>
    <span style="color:#9966CC; font-weight:bold;">for</span> header <span style="color:#9966CC; font-weight:bold;">in</span> request.<span style="color:#9900CC;">env</span>.<span style="color:#CC0066; font-weight:bold;">select</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>k,v<span style="color:#006600; font-weight:bold;">|</span> k.<span style="color:#9900CC;">match</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;^HTTP.*&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
        logger.<span style="color:#9900CC;">info</span><span style="color:#006600; font-weight:bold;">&#40;</span>header<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#CC0066; font-weight:bold;">split</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'_'</span>,<span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;:&quot;</span> <span style="color:#006600; font-weight:bold;">+</span> header<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</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></pre></div></div>

<p>Reference:<br />
<a href="http://tonycode.com/wiki/index.php?title=Dumping_HTTP_Headers">http://tonycode.com/wiki/index.php?title=Dumping_HTTP_Headers</a></p>
<p>2. However, please note that you can actually see everything from the request as parameters.</p>
<p> Parameters: {&#8220;MSAG-ADDRESS-PREFIX&#8221;=>&#8221;aSTARTa&#8221;, &#8220;format&#8221;=>&#8221;xml&#8221;, &#8220;protocol&#8221;=>&#8221;ussd&#8221;, &#8220;user-agent&#8221;=>&#8221;Jakarta Commons-HttpClient/3.0.1&#8243;, &#8220;WHOISD-ABONENT&#8221;=>&#8221;8613520747210&#8243;, &#8220;action&#8221;=>&#8221;menu&#8221;, &#8220;controller&#8221;=>&#8221;ussd&#8221;, &#8220;subscriberID&#8221;=>&#8221;8613520747210&#8243;, &#8220;WHOISD-USR&#8221;=>&#8221;-1&#8243;, &#8220;host&#8221;=>&#8221;wap.watago.mobi&#8221;, &#8220;WHOISD-USSD-MESSAGE&#8221;=>&#8221;", &#8220;content-length&#8221;=>&#8221;0&#8243;}</p>
<p>This means we can easily do..</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#0066ff; font-weight:bold;">@whoisd_abonent</span> = params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'WHOISD-ABONENT'</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">||</span> <span style="color:#0000FF; font-weight:bold;">nil</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2008/11/rubyonrails-getting-http-headers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails Note #8: Testing with session variables</title>
		<link>/wordpress/2008/11/testing-with-session-variables/</link>
		<comments>/wordpress/2008/11/testing-with-session-variables/#comments</comments>
		<pubDate>Tue, 18 Nov 2008 11:23:35 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">/wordpress/?p=297</guid>
		<description><![CDATA[Taken from http://guides.rails.info/testing_rails_applications.html The get method kicks off the web request and populates the results into the response. It accepts 4 arguments: *The action of the controller you are requesting. This can be in the form of a string or a symbol. *An optional hash of request parameters to pass into the action (eg. query [...]]]></description>
			<content:encoded><![CDATA[<p>Taken from <a href="http://guides.rails.info/testing_rails_applications.html">http://guides.rails.info/testing_rails_applications.html</a></p>
<p>The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:</p>
<p>    *The action of the controller you are requesting. This can be in the form of a string or a symbol.<br />
    *An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).<br />
    *An optional hash of session variables to pass along with the request.<br />
    *An optional hash of flash values.</p>
<p>Example: Calling the :show action, passing an id of 12 as the params and setting a user_id of 5 in the session:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">get<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:show</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">'id'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;12&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">'user_id'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">5</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2008/11/testing-with-session-variables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails Note #7: NIL in Fixtures</title>
		<link>/wordpress/2008/11/be-careful-with-your-fixtures/</link>
		<comments>/wordpress/2008/11/be-careful-with-your-fixtures/#comments</comments>
		<pubDate>Tue, 18 Nov 2008 07:19:11 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">/wordpress/?p=294</guid>
		<description><![CDATA[If you want user_id to be &#8216;nil&#8217;, then omit it from your fixtures. I tried setting user_id: nil before, and it turned out to be &#8217;0&#8242; in the database. # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html &#60;% u = UserLogin.create&#40; :password =&#62; 'foo'&#41; %&#62; &#60;% u.password=&#40;'password'&#41; %&#62; &#160; user_no_profile: email: noprofile@yahoo.com admin: false user_id: nil salt: [...]]]></description>
			<content:encoded><![CDATA[<p>If you want user_id to be &#8216;nil&#8217;, then omit it from your fixtures. I tried setting user_id: nil before, and it turned out to be &#8217;0&#8242; in the database.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"># Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
<span style="color:#006600; font-weight:bold;">&lt;%</span> u = UserLogin.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#ff3333; font-weight:bold;">:password</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'foo'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;%</span> u.<span style="color:#9900CC;">password</span>=<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'password'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
&nbsp;
user_no_profile:
 email: noprofile@yahoo.com
 admin: false
 user_id: nil
 salt: <span style="color:#006600; font-weight:bold;">&lt;%</span>= u.<span style="color:#9900CC;">salt</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 salted_password: <span style="color:#006600; font-weight:bold;">&lt;%</span>= u.<span style="color:#9900CC;">salted_password</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></div></div>

<p><img src="/wordpress/wp-content/uploads/2008/11/picture-3.png" alt="Picture 3.png" border="0" width="640" height="60" /></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"># Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
<span style="color:#006600; font-weight:bold;">&lt;%</span> u = UserLogin.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#ff3333; font-weight:bold;">:password</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'foo'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;%</span> u.<span style="color:#9900CC;">password</span>=<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'password'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
&nbsp;
user_no_profile:
 email: noprofile@yahoo.com
 admin: false
 salt: <span style="color:#006600; font-weight:bold;">&lt;%</span>= u.<span style="color:#9900CC;">salt</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 salted_password: <span style="color:#006600; font-weight:bold;">&lt;%</span>= u.<span style="color:#9900CC;">salted_password</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></div></div>

<p><img src="/wordpress/wp-content/uploads/2008/11/picture-21.png" alt="Picture 2.png" border="0" width="680" height="61" /></p>
<p><em>Before pulling your hair out on what went wrong with your functional tests, check the test database if you have the correct values in your records.</em>  Remember <strong>&#8217;0&#8242;</strong> is different from <strong>&#8216;nil&#8217;</strong>.</p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2008/11/be-careful-with-your-fixtures/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails Note #6: Pagination</title>
		<link>/wordpress/2008/11/ruby-on-rails-pagination/</link>
		<comments>/wordpress/2008/11/ruby-on-rails-pagination/#comments</comments>
		<pubDate>Sun, 16 Nov 2008 01:15:43 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">/wordpress/?p=293</guid>
		<description><![CDATA[1. will_paginate docs Main http://github.com/mislav/will_paginate/wikis Reference http://mislav.uniqpath.com/static/will_paginate/doc/ Clone URL: git://github.com/mislav/will_paginate.git 2. Installation as a gem http://github.com/mislav/will_paginate/wikis/installation gem sources -a http://gems.github.com Once installed, do script/server 3. Controller class PoiAppController &#60; ApplicationController def poi_by_category mylimit = 100 sql = &#34;SELECT pa.* FROM poi_apps pa WHERE pa.id IN &#34; + &#34;(&#34; + &#34;SELECT pc.poi_app_id &#34; + &#34;FROM poi_categories [...]]]></description>
			<content:encoded><![CDATA[<p>1. will_paginate docs<br />
Main <a href="http://github.com/mislav/will_paginate/wikis">http://github.com/mislav/will_paginate/wikis</a><br />
Reference <a href="http://mislav.uniqpath.com/static/will_paginate/doc/">http://mislav.uniqpath.com/static/will_paginate/doc/</a><br />
Clone URL: <a href="http://mislav.uniqpath.com/static/will_paginate/doc/">git://github.com/mislav/will_paginate.git</a></p>
<p>2. Installation as a gem<br />
<a href="http://github.com/mislav/will_paginate/wikis/installation">http://github.com/mislav/will_paginate/wikis/installation</a><br />
gem sources -a http://gems.github.com</p>
<p>Once installed, do <strong>script/server</strong> </p>
<p>3. Controller</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> PoiAppController <span style="color:#006600; font-weight:bold;">&lt;</span> ApplicationController 
  <span style="color:#9966CC; font-weight:bold;">def</span> poi_by_category
	mylimit = <span style="color:#006666;">100</span>
    sql = <span style="color:#996600;">&quot;SELECT pa.* FROM poi_apps pa WHERE pa.id IN &quot;</span> <span style="color:#006600; font-weight:bold;">+</span>
          <span style="color:#996600;">&quot;(&quot;</span> <span style="color:#006600; font-weight:bold;">+</span>
			  <span style="color:#996600;">&quot;SELECT pc.poi_app_id &quot;</span> <span style="color:#006600; font-weight:bold;">+</span>
			  <span style="color:#996600;">&quot;FROM poi_categories pc &quot;</span> <span style="color:#006600; font-weight:bold;">+</span>
			  <span style="color:#996600;">&quot;WHERE pc.categ_node_id LIKE '&quot;</span> <span style="color:#006600; font-weight:bold;">+</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:node_id</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;%%'&quot;</span> <span style="color:#006600; font-weight:bold;">+</span>
			  <span style="color:#996600;">&quot;LIMIT &quot;</span> <span style="color:#006600; font-weight:bold;">+</span> mylimit.<span style="color:#9900CC;">to_s</span> <span style="color:#006600; font-weight:bold;">+</span>
          <span style="color:#996600;">&quot;)&quot;</span>
    <span style="color:#008000; font-style:italic;">#@poi_apps = PoiApp.find_by_sql(sql)</span>
    <span style="color:#0066ff; font-weight:bold;">@poi_apps</span> = PoiApp.<span style="color:#9900CC;">paginate_by_sql</span> <span style="color:#006600; font-weight:bold;">&#91;</span>sql<span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#ff3333; font-weight:bold;">:page</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:page</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#ff3333; font-weight:bold;">:per_page</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">10</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>4. View</p>

<div class="wp_syntax"><div class="code"><pre class="erb" style="font-family:monospace;">&lt;h2&gt;POIs&lt;/h2&gt;
&nbsp;
&lt;div clas=&quot;page_info&quot;&gt;
  &lt;%= page_entries_info @poi_apps %&gt;
&lt;/div&gt;
&nbsp;
&lt;table&gt;
  &lt;tr&gt;
    &lt;td&gt;POI_APP_ID&lt;/td&gt;
    &lt;td&gt;CN_NAME&lt;/td&gt;
  	&lt;td&gt;EN_NAME&lt;/td&gt;
  &lt;/tr&gt;
	&lt;% for poi in @poi_apps %&gt;
	&lt;tr&gt;
	  &lt;td&gt;&lt;%= poi.id %&gt;&lt;/td&gt;
	  &lt;td&gt;&lt;%= poi.cn_name %&gt;&lt;/td&gt;
		&lt;td&gt;&lt;%= poi.en_name %&gt;&lt;/td&gt;
	&lt;/tr&gt;
	&lt;% end %&gt;
&lt;/table&gt;
&nbsp;
&lt;%= will_paginate @poi_apps %&gt;</pre></div></div>

<p>5. Checkout the styles <a href="http://mislav.uniqpath.com/static/will_paginate/">http://mislav.uniqpath.com/static/will_paginate/</a></p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2008/11/ruby-on-rails-pagination/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

