<?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/category/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 #15: Rails 3, Devise, Cucumber</title>
		<link>/wordpress/2011/02/rails-note-15-rails-3-2/</link>
		<comments>/wordpress/2011/02/rails-note-15-rails-3-2/#comments</comments>
		<pubDate>Wed, 09 Feb 2011 06:21:24 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[rails3]]></category>

		<guid isPermaLink="false">/wordpress/?p=819</guid>
		<description><![CDATA[1. Installed rvm (Ruby Version Manager). See Episode 200. Rails3 Beta and RVM rupert:tsa rupert$ rvm ruby-1.9.2-p0 rupert:tsa rupert$ ruby -v ruby 1.9.2p0 &#40;2010-08-18 revision 29036&#41; &#91;x86_64-darwin10.5.0&#93; To use ruby-1.9.2-p0 as default rupert:rails3 rupert$ rvm ruby-1.9.2-p0 --default rupert:rails3 rupert$ ruby -v ruby 1.9.2p0 &#40;2010-08-18 revision 29036&#41; &#91;x86_64-darwin10.5.0&#93; 2. Install rails3 gem install rails 3. Create [...]]]></description>
			<content:encoded><![CDATA[<p>1. <strong>Installed rvm (Ruby Version Manager).</strong> See <a href="http://railscasts.com/episodes/200-rails-3-beta-and-rvm">Episode 200. Rails3 Beta and RVM</a></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rupert:tsa rupert$ rvm ruby-1.9.2-p0
rupert:tsa rupert$ ruby <span style="color: #660033;">-v</span>
ruby 1.9.2p0 <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">2010</span>-08-<span style="color: #000000;">18</span> revision <span style="color: #000000;">29036</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>x86_64-darwin10.5.0<span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>

<p>To use ruby-1.9.2-p0 as default</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rupert:rails3 rupert$ rvm ruby-1.9.2-p0 <span style="color: #660033;">--default</span>
rupert:rails3 rupert$ ruby <span style="color: #660033;">-v</span>
ruby 1.9.2p0 <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">2010</span>-08-<span style="color: #000000;">18</span> revision <span style="color: #000000;">29036</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>x86_64-darwin10.5.0<span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>

<p>2. <strong>Install rails3</strong></p>

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

<p>3. <strong>Create a rails app tsa</strong> (the sample app)</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rails new tsa <span style="color: #660033;">-d</span> mysql</pre></div></div>

<p>4. Start webrick. Yup, script/server is gone</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rupert:tsa rupert$ rails server <span style="color: #660033;">-e</span> development
=<span style="color: #000000; font-weight: bold;">&gt;</span> Booting WEBrick
=<span style="color: #000000; font-weight: bold;">&gt;</span> Rails 3.0.3 application starting <span style="color: #000000; font-weight: bold;">in</span> production on http:<span style="color: #000000; font-weight: bold;">//</span>0.0.0.0:<span style="color: #000000;">3000</span>
=<span style="color: #000000; font-weight: bold;">&gt;</span> Call with <span style="color: #660033;">-d</span> to detach
=<span style="color: #000000; font-weight: bold;">&gt;</span> Ctrl-C to shutdown server
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2010</span>-<span style="color: #000000;">12</span>-06 <span style="color: #000000;">20</span>:<span style="color: #000000;">47</span>:<span style="color: #000000;">27</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> INFO  WEBrick 1.3.1
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2010</span>-<span style="color: #000000;">12</span>-06 <span style="color: #000000;">20</span>:<span style="color: #000000;">47</span>:<span style="color: #000000;">27</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> INFO  ruby 1.9.2 <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">2010</span>-08-<span style="color: #000000;">18</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>x86_64-darwin10.5.0<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2010</span>-<span style="color: #000000;">12</span>-06 <span style="color: #000000;">20</span>:<span style="color: #000000;">47</span>:<span style="color: #000000;">27</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> INFO  WEBrick::HTTPServer<span style="color: #666666; font-style: italic;">#start: pid=1348 port=3000</span></pre></div></div>

<p>Note: Upon checking http://127.0.0.1:3000/ I get a &#8220;Routing Error&#8221;</p>
<p>5. <strong>Update your GemFile with the necessary gems.</strong><br />
Let&#8217;s use devise as a login authentication system.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">source <span style="color:#996600;">'http://rubygems.org'</span>
&nbsp;
gem <span style="color:#996600;">'rails'</span>, <span style="color:#996600;">'3.0.3'</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Bundle edge Rails instead:</span>
<span style="color:#008000; font-style:italic;"># gem 'rails', :git =&gt; 'git://github.com/rails/rails.git'</span>
&nbsp;
gem <span style="color:#996600;">'mysql2'</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></pre></div></div>

<p>Then run <strong>bundle install</strong>. This will install devise gem.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rupert:tsa rupert$ bundle <span style="color: #c20cb9; font-weight: bold;">install</span>
Fetching 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
remote: Counting objects: <span style="color: #000000;">10326</span>, done.
remote: Compressing objects: <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">3745</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">3745</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, done.
remote: Total <span style="color: #000000;">10326</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>delta <span style="color: #000000;">6603</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, reused <span style="color: #000000;">9755</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>delta <span style="color: #000000;">6163</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
Receiving objects: <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">10326</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">10326</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #000000;">1.24</span> MiB <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000;">314</span> KiB<span style="color: #000000; font-weight: bold;">/</span>s, done.
Resolving deltas: <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">6603</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">6603</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, done.
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></pre></div></div>

<p>Where are the gems installed?</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rupert:tsa rupert$ bundle show devise
<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-p0<span style="color: #000000; font-weight: bold;">/</span>bundler<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>devise-b50fd1a72e71</pre></div></div>

<p>6. <strong>Create the necessary databases in mysql.</strong> See config/database.yml</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">DATABASE</span> tsa_development;</pre></div></div>

<p>7. <strong>Run devise generator.</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rupert:tsa rupert$ rails generate devise:<span style="color: #c20cb9; font-weight: bold;">install</span>
      create  config<span style="color: #000000; font-weight: bold;">/</span>initializers<span style="color: #000000; font-weight: bold;">/</span>devise.rb
      create  config<span style="color: #000000; font-weight: bold;">/</span>locales<span style="color: #000000; font-weight: bold;">/</span>devise.en.yml
&nbsp;
===============================================================================
&nbsp;
Some setup you must <span style="color: #000000; font-weight: bold;">do</span> manually <span style="color: #000000; font-weight: bold;">if</span> you havent yet:
&nbsp;
  1. Setup default url options <span style="color: #000000; font-weight: bold;">for</span> your specific environment. Here is an
     example of development environment:
&nbsp;
       config.action_mailer.default_url_options = <span style="color: #7a0874; font-weight: bold;">&#123;</span> :host =<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #ff0000;">'localhost:3000'</span> <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&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 <span style="color: #000000; font-weight: bold;">*</span>something<span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">in</span> your config<span style="color: #000000; font-weight: bold;">/</span>routes.rb.
     For example:
&nbsp;
       root :to =<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #ff0000;">&quot;home#index&quot;</span>
&nbsp;
  3. Ensure you have flash messages <span style="color: #000000; font-weight: bold;">in</span> app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>layouts<span style="color: #000000; font-weight: bold;">/</span>application.html.erb.
     For example:
&nbsp;
       <span style="color: #000000; font-weight: bold;">&lt;</span>p <span style="color: #007800;">class</span>=<span style="color: #ff0000;">&quot;notice&quot;</span><span style="color: #000000; font-weight: bold;">&gt;&lt;%</span>= notice <span style="color: #000000; font-weight: bold;">%&gt;&lt;/</span>p<span style="color: #000000; font-weight: bold;">&gt;</span>
       <span style="color: #000000; font-weight: bold;">&lt;</span>p <span style="color: #007800;">class</span>=<span style="color: #ff0000;">&quot;alert&quot;</span><span style="color: #000000; font-weight: bold;">&gt;&lt;%</span>= alert <span style="color: #000000; font-weight: bold;">%&gt;&lt;/</span>p<span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
===============================================================================</pre></div></div>

<p>8. <strong>Generate a controller in Rails3.</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rupert:tsa rupert$ rails generate controller main index
      create  app<span style="color: #000000; font-weight: bold;">/</span>controllers<span style="color: #000000; font-weight: bold;">/</span>main_controller.rb
       route  get <span style="color: #ff0000;">&quot;main/index&quot;</span>
      invoke  erb
      create    app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>main
      create    app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>main<span style="color: #000000; font-weight: bold;">/</span>index.html.erb
      invoke  test_unit
      create    test<span style="color: #000000; font-weight: bold;">/</span>functional<span style="color: #000000; font-weight: bold;">/</span>main_controller_test.rb
      invoke  helper
      create    app<span style="color: #000000; font-weight: bold;">/</span>helpers<span style="color: #000000; font-weight: bold;">/</span>main_helper.rb
      invoke    test_unit
      create      test<span style="color: #000000; font-weight: bold;">/</span>unit<span style="color: #000000; font-weight: bold;">/</span>helpers<span style="color: #000000; font-weight: bold;">/</span>main_helper_test.rb</pre></div></div>

<p>Update routes.rb for the root_url</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  root <span style="color:#ff3333; font-weight:bold;">:to</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;main#index&quot;</span></pre></div></div>

<p>9. Create a User model with devise.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rupert:tsa rupert$ rails generate devise User
      invoke  active_record
      create    app<span style="color: #000000; font-weight: bold;">/</span>models<span style="color: #000000; font-weight: bold;">/</span>user.rb
      invoke    test_unit
      create      test<span style="color: #000000; font-weight: bold;">/</span>unit<span style="color: #000000; font-weight: bold;">/</span>user_test.rb
      create      test<span style="color: #000000; font-weight: bold;">/</span>fixtures<span style="color: #000000; font-weight: bold;">/</span>users.yml
      create    db<span style="color: #000000; font-weight: bold;">/</span>migrate<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">20101206104321</span>_devise_create_users.rb
      insert    app<span style="color: #000000; font-weight: bold;">/</span>models<span style="color: #000000; font-weight: bold;">/</span>user.rb
       route  devise_for :<span style="color: #c20cb9; font-weight: bold;">users</span>
rupert:tsa rupert$</pre></div></div>

<p>10. Run migration for User model</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rupert:tsa rupert$ <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">RAILS_ENV</span>=development
rupert:tsa rupert$ rake db:migrate
<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">in</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>projects<span style="color: #000000; font-weight: bold;">/</span>rails3<span style="color: #000000; font-weight: bold;">/</span>tsa<span style="color: #7a0874; font-weight: bold;">&#41;</span>
==  DeviseCreateUsers: migrating ==============================================
<span style="color: #660033;">--</span> create_table<span style="color: #7a0874; font-weight: bold;">&#40;</span>:<span style="color: #c20cb9; font-weight: bold;">users</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
   -<span style="color: #000000; font-weight: bold;">&gt;</span> 0.0805s
<span style="color: #660033;">--</span> add_index<span style="color: #7a0874; font-weight: bold;">&#40;</span>:<span style="color: #c20cb9; font-weight: bold;">users</span>, :email, <span style="color: #7a0874; font-weight: bold;">&#123;</span>:<span style="color: #007800;">unique</span>=<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #c20cb9; font-weight: bold;">true</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
   -<span style="color: #000000; font-weight: bold;">&gt;</span> 0.1368s
<span style="color: #660033;">--</span> add_index<span style="color: #7a0874; font-weight: bold;">&#40;</span>:<span style="color: #c20cb9; font-weight: bold;">users</span>, :reset_password_token, <span style="color: #7a0874; font-weight: bold;">&#123;</span>:<span style="color: #007800;">unique</span>=<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #c20cb9; font-weight: bold;">true</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
   -<span style="color: #000000; font-weight: bold;">&gt;</span> 0.1484s
==  DeviseCreateUsers: migrated <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.3662s<span style="color: #7a0874; font-weight: bold;">&#41;</span> =====================================</pre></div></div>

<p>11. Using cucumber</p>

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

<p>12. Update Gemfile</p>

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

<p>13. Rspec</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rupert:tsa rupert$ rails g rspec:<span style="color: #c20cb9; font-weight: bold;">install</span>
      create  .rspec
      create  spec
      create  spec<span style="color: #000000; font-weight: bold;">/</span>spec_helper.rb
      create  autotest
      create  autotest<span style="color: #000000; font-weight: bold;">/</span>discover.rb</pre></div></div>

<p>14. Cucumber</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rupert:tsa rupert$ rails g cucumber:<span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">--rspec</span> <span style="color: #660033;">--capybara</span>
      create  config<span style="color: #000000; font-weight: bold;">/</span>cucumber.yml
      create  script<span style="color: #000000; font-weight: bold;">/</span>cucumber
       <span style="color: #c20cb9; font-weight: bold;">chmod</span>  script<span style="color: #000000; font-weight: bold;">/</span>cucumber
      create  features<span style="color: #000000; font-weight: bold;">/</span>step_definitions
      create  features<span style="color: #000000; font-weight: bold;">/</span>step_definitions<span style="color: #000000; font-weight: bold;">/</span>web_steps.rb
      create  features<span style="color: #000000; font-weight: bold;">/</span>support
      create  features<span style="color: #000000; font-weight: bold;">/</span>support<span style="color: #000000; font-weight: bold;">/</span>paths.rb
      create  features<span style="color: #000000; font-weight: bold;">/</span>support<span style="color: #000000; font-weight: bold;">/</span>env.rb
       exist  lib<span style="color: #000000; font-weight: bold;">/</span>tasks
      create  lib<span style="color: #000000; font-weight: bold;">/</span>tasks<span style="color: #000000; font-weight: bold;">/</span>cucumber.rake
        gsub  config<span style="color: #000000; font-weight: bold;">/</span>database.yml
        gsub  config<span style="color: #000000; font-weight: bold;">/</span>database.yml
       force  config<span style="color: #000000; font-weight: bold;">/</span>database.yml</pre></div></div>

<p>15. Write your first feature</p>

<div class="wp_syntax"><div class="code"><pre class="cucumber" style="font-family:monospace;">Feature: Home Page
  In order to make sure the home page works
  As a normal user
  I want to see the home page
&nbsp;
Scenario: Show Main Sections
  When I go to the home page
  Then show me the page
  Then I should see &quot;Login&quot;</pre></div></div>

<p>From <a href="http://rubylearning.com/blog/2010/10/05/outside-in-development/">Harold Jimenez</a>:</p>
<blockquote><p><em>&#8220;The Given step is where you set up the context of your scenario. Every scenario starts with a blank slate, so it is important to create a state in your application for example by creating data in the database, or by navigating to a specific page. </p>
<p>The When step is where you exercise the application in order to accomplish what needs testing. In the case of a web app like twiddr, this is usually where you fill in forms, press buttons, click links, or otherwise interact with the system in some way. </p>
<p>Finally, the Then step is where you verify the result, and it’s where we check that the correct pages are rendered, that we see a success or error message, or anything that could help us verify that the prior action was successful. As we move along with creating our own features, this will become much clearer.&#8221;</em></p></blockquote>
<p>16. See it fail in cucumber</p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">rake features  (or)
cucumber (or)
bundle exec cucumber features/home.feature</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">rupert:tsa rupert$ cucumber
Using the default profile...
F--
&nbsp;
(::) failed steps (::)
&nbsp;
Can't find mapping from &quot;the home page&quot; to a path.
Now, go and add a mapping in /Users/rupert/projects/rails3/tsa/tsa/features/support/paths.rb (RuntimeError)
./features/support/paths.rb:26:in `rescue in path_to'
./features/support/paths.rb:20:in `path_to'
./features/step_definitions/web_steps.rb:24:in `/^(?:|I )go to (.+)$/'
features/home.feature:7:in `When I go to the home page'
&nbsp;
Failing Scenarios:
cucumber features/home.feature:6 # Scenario: Show Main Sections
&nbsp;
1 scenario (1 failed)
3 steps (1 failed, 2 skipped)
0m0.062s</pre></div></div>

<p>17. Defining &#8220;the home page&#8221; in the <strong>support/paths.rb</strong></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">    <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#006600; font-weight:bold;">/</span>the home page<span style="color:#006600; font-weight:bold;">/</span>
      root_path</pre></div></div>

<p>and in the routes.rb</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">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></pre></div></div>

<p>Other examples:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#006600; font-weight:bold;">/</span>the profile page <span style="color:#9966CC; font-weight:bold;">for</span> <span style="color:#996600;">&quot;([^<span style="color:#000099;">\&quot;</span>]+)&quot;</span><span style="color:#006600; font-weight:bold;">/</span>
  user = User.<span style="color:#9900CC;">find_by_twiddr_name</span>!<span style="color:#006600; font-weight:bold;">&#40;</span>$<span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  user_path<span style="color:#006600; font-weight:bold;">&#40;</span>user<span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>Note: When you see the error</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">undefined local variable <span style="color:#9966CC; font-weight:bold;">or</span> method <span style="color:#996600;">`node' for #&lt;Capybara::Driver::RackTest::Node:0x00000101151ad8&gt; (NameError)&quot;</span></pre></div></div>

<p>You need to comment in features/support/env.rb</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#require 'cucumber/rails/capybara_javascript_emulation'</span></pre></div></div>

<p>For more info, read <a href="https://rspec.lighthouseapp.com/projects/16211-cucumber/tickets/674">https://rspec.lighthouseapp.com/projects/16211-cucumber/tickets/674</a></p>
<p>18. Then show me the page will open up the browser</p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">file://localhost/Users/rupert/projects/rails3/tsa/tsa/tmp/capybara/capybara-20101209222149.html</pre></div></div>

<p>19. Automatic Testing with &#8220;autotest&#8221;.  When you save a file, autotest automatically runs cucumber.  To avoid autotest infinite loop with cucumber, make sure your IDE (i.e rubymine) does not save automatically in the file system.  You can exclude files and directories from autotest with a &#8220;.autotest&#8221; file</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">Autotest.<span style="color:#9900CC;">add_hook</span> <span style="color:#ff3333; font-weight:bold;">:initialize</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>at<span style="color:#006600; font-weight:bold;">|</span>
  at.<span style="color:#9900CC;">add_exception</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">%</span>r<span style="color:#006600; font-weight:bold;">&#123;</span>^\.<span style="color:#006600; font-weight:bold;">/</span>\.<span style="color:#9900CC;">git</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  at.<span style="color:#9900CC;">add_exception</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">%</span>r<span style="color:#006600; font-weight:bold;">&#123;</span>^\.<span style="color:#006600; font-weight:bold;">/</span>db<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  at.<span style="color:#9900CC;">add_exception</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">%</span>r<span style="color:#006600; font-weight:bold;">&#123;</span>^\.<span style="color:#006600; font-weight:bold;">/</span>log<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  at.<span style="color:#9900CC;">add_exception</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">%</span>r<span style="color:#006600; font-weight:bold;">&#123;</span>^\.<span style="color:#006600; font-weight:bold;">/</span>tmp<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  at.<span style="color:#9900CC;">add_exception</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">%</span>r<span style="color:#006600; font-weight:bold;">&#123;</span>^\.<span style="color:#006600; font-weight:bold;">/</span>.<span style="color:#9900CC;">idea</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  at.<span style="color:#9900CC;">add_exception</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">%</span>r<span style="color:#006600; font-weight:bold;">&#123;</span>^\.<span style="color:#006600; font-weight:bold;">/</span>rerun\.<span style="color:#9900CC;">txt</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  at.<span style="color:#9900CC;">add_exception</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">%</span>r<span style="color:#006600; font-weight:bold;">&#123;</span>^\.<span style="color:#006600; font-weight:bold;">/</span>Gemfile\.<span style="color:#9900CC;">lock</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Now you can run, autotest from the terminal. Save a file and see autotest run.</p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">autotest</pre></div></div>

<p>20. If you have javascript AJAX calls included in cucumber scenarios, you need to append them with @javascript tag.  Below is a sample which selects &#8220;Australia&#8221; from the &#8220;Country&#8221; and waits for the ajax request to finish before selecting the &#8220;State&#8221; drop down. More info on <a href="https://github.com/jnicklas/capybara">capybara github</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="gherkin" style="font-family:monospace;">@javascript
Scenario: Creating a Fleet
  And I select &quot;Australia&quot; from &quot;Country&quot;
  And I wait for the ajax request to finish
  And I select &quot;Victoria&quot; from &quot;State&quot;</pre></div></div>

<p>How does the step &#8220;I wait for the ajax request to finish&#8221; looks like? <a href="http://stackoverflow.com/questions/7286254/cucumber-wait-for-ajaxsuccess">http://stackoverflow.com/questions/7286254/cucumber-wait-for-ajaxsuccess</a></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">When</span> <span style="color:#006600; font-weight:bold;">/</span>^I wait <span style="color:#9966CC; font-weight:bold;">for</span> the ajax request to finish$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  start_time = <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>
  page.<span style="color:#9900CC;">evaluate_script</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'jQuery.isReady&amp;&amp;jQuery.active==0'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9966CC; font-weight:bold;">class</span>.<span style="color:#9900CC;">should_not</span> eql<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">String</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">until</span> page.<span style="color:#9900CC;">evaluate_script</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'jQuery.isReady&amp;&amp;jQuery.active==0'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">or</span> <span style="color:#006600; font-weight:bold;">&#40;</span>start_time <span style="color:#006600; font-weight:bold;">+</span> 5.<span style="color:#9900CC;">seconds</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>
    <span style="color:#CC0066; font-weight:bold;">sleep</span> <span style="color:#006666;">1</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2011/02/rails-note-15-rails-3-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails Note #14: QuickStart Tutorial</title>
		<link>/wordpress/2010/02/ruby-on-rails-quickstart-tutorial/</link>
		<comments>/wordpress/2010/02/ruby-on-rails-quickstart-tutorial/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 05:39:31 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[rails3]]></category>

		<guid isPermaLink="false">/wordpress/?p=707</guid>
		<description><![CDATA[If you haven&#8217;t installed ruby, follow this post Part 1: Installation and Configuration (Rails and Passenger) 1. Upgrade existing ruby gems sudo gem list sudo gem update --system UPDATE: Took me 4 hours figuring this out. There was a problem when i run script/console that it will say the &#8220;gem&#8221; detected was 1.0.1 although the [...]]]></description>
			<content:encoded><![CDATA[<p>If you haven&#8217;t installed ruby, follow this <a href="/wordpress/2008/11/getting-my-feet-wet-in-ruby-on-rails/">post</a></p>
<p><strong>Part 1: Installation and Configuration (Rails and Passenger)</strong></p>
<p>1. Upgrade existing ruby gems</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> gem list
<span style="color: #c20cb9; font-weight: bold;">sudo</span> gem update <span style="color: #660033;">--system</span></pre></div></div>

<p>UPDATE: Took me 4 hours figuring this out. There was a problem when i run script/console that it will say the &#8220;gem&#8221; detected was 1.0.1 although the current gem version is 1.3.5 after gem update &#8211;system. Google didn&#8217;t helped out. But I was able to nail down the problem from this post:</p>
<p><a href="https://wincent.com/wiki/Upgrading_to_RubyGems_1.0.1_on_Mac_OS_X_10.5.1">https://wincent.com/wiki/Upgrading_to_RubyGems_1.0.1_on_Mac_OS_X_10.5.1</a><br />
In the post above, notice that rubygems 1.0.1 was installed in /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin. I guess this gem was being referenced first before the actual /usr/local/bin/gem. So I deleted this directory /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr.</p>
<p>Possible sources of gem installations:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><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>.gem<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>gems
<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Ruby<span style="color: #000000; font-weight: bold;">/</span>Gems<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>gems</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rupert:<span style="color: #000000;">1.8</span> rupert$ gem <span style="color: #c20cb9; font-weight: bold;">env</span>
RubyGems Environment:
  - RUBYGEMS VERSION: 1.3.5
  - RUBY VERSION: 1.8.6 <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">2008</span>-08-08 patchlevel <span style="color: #000000;">286</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>i686-darwin9.5.0<span style="color: #7a0874; font-weight: bold;">&#93;</span>
  - INSTALLATION DIRECTORY: <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span>
  - RUBY EXECUTABLE: <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ruby
  - EXECUTABLE DIRECTORY: <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86-darwin-<span style="color: #000000;">9</span>
  - GEM PATHS:
     - <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</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>.gem<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span>
  - GEM CONFIGURATION:
     - :update_sources =<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #c20cb9; font-weight: bold;">true</span>
     - :verbose =<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #c20cb9; font-weight: bold;">true</span>
     - :benchmark =<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #c20cb9; font-weight: bold;">false</span>
     - :backtrace =<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #c20cb9; font-weight: bold;">false</span>
     - :bulk_threshold =<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000;">1000</span>
  - REMOTE SOURCES:
     - http:<span style="color: #000000; font-weight: bold;">//</span>gems.rubyforge.org<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>2. Install rails. Download from ruby-forge. Link?</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gem <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-V</span> rails-2.3.3.gem
gem <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-V</span> mysql</pre></div></div>

<p>3. Install and configure passenger for Apache2</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gem <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-V</span> passenger
<span style="color: #7a0874; font-weight: bold;">cd</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>.gem<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>passenger-2.2.5<span style="color: #000000; font-weight: bold;">/</span>bin
passenger-install-apache2-module</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;">469 LoadModule passenger_module /Users/rupert/.gem/ruby/1.8/gems/passenger-2.2.5/ext/apache2/mod_passenger.so
470 PassengerRoot /Users/rupert/.gem/ruby/1.8/gems/passenger-2.2.5
471 PassengerRuby /usr/local/bin/ruby
472 
473 &lt;VirtualHost *:80&gt;
474   RailsBaseURI /rails/travelsiteph
475 &lt;/VirtualHost&gt;</pre></div></div>

<p>4. Create a sample rails project (&#8220;travelsiteph&#8221;) in your project directory (&#8220;/Users/rupert/projects/rails&#8221;).</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">cd</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>projects<span style="color: #000000; font-weight: bold;">/</span>rails
$ rails travelisteph
      create  
      create  app<span style="color: #000000; font-weight: bold;">/</span>controllers
      create  app<span style="color: #000000; font-weight: bold;">/</span>helpers
      create  app<span style="color: #000000; font-weight: bold;">/</span>models
      create  app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>layouts
      create  config<span style="color: #000000; font-weight: bold;">/</span>environments
	.....
$ <span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-la</span> travelsiteph
drwxr-xr-x  <span style="color: #000000;">15</span> rupert  admin    <span style="color: #000000;">510</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">21</span>:<span style="color: #000000;">14</span> .
drwxr-xr-x   <span style="color: #000000;">5</span> rupert  admin    <span style="color: #000000;">170</span> <span style="color: #000000;">30</span> Sep <span style="color: #000000;">16</span>:<span style="color: #000000;">31</span> ..
<span style="color: #660033;">-rw-r--r--</span>   <span style="color: #000000;">1</span> rupert  admin  <span style="color: #000000;">10011</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">21</span>:<span style="color: #000000;">14</span> README
<span style="color: #660033;">-rw-r--r--</span>   <span style="color: #000000;">1</span> rupert  admin    <span style="color: #000000;">307</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">21</span>:<span style="color: #000000;">14</span> Rakefile
drwxr-xr-x   <span style="color: #000000;">6</span> rupert  admin    <span style="color: #000000;">204</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">21</span>:<span style="color: #000000;">14</span> app
drwxr-xr-x   <span style="color: #000000;">9</span> rupert  admin    <span style="color: #000000;">306</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">21</span>:<span style="color: #000000;">14</span> config
drwxr-xr-x   <span style="color: #000000;">4</span> rupert  admin    <span style="color: #000000;">136</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">21</span>:<span style="color: #000000;">18</span> db
drwxr-xr-x   <span style="color: #000000;">3</span> rupert  admin    <span style="color: #000000;">102</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">21</span>:<span style="color: #000000;">14</span> doc
drwxr-xr-x   <span style="color: #000000;">3</span> rupert  admin    <span style="color: #000000;">102</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">21</span>:<span style="color: #000000;">14</span> lib
drwxr-xr-x   <span style="color: #000000;">6</span> rupert  admin    <span style="color: #000000;">204</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">21</span>:<span style="color: #000000;">14</span> log
drwxr-xr-x  <span style="color: #000000;">11</span> rupert  admin    <span style="color: #000000;">374</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">21</span>:<span style="color: #000000;">14</span> public
drwxr-xr-x  <span style="color: #000000;">11</span> rupert  admin    <span style="color: #000000;">374</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">21</span>:<span style="color: #000000;">14</span> script
drwxr-xr-x   <span style="color: #000000;">8</span> rupert  admin    <span style="color: #000000;">272</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">21</span>:<span style="color: #000000;">55</span> <span style="color: #7a0874; font-weight: bold;">test</span>
drwxr-xr-x   <span style="color: #000000;">6</span> rupert  admin    <span style="color: #000000;">204</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">22</span>:07 tmp
drwxr-xr-x   <span style="color: #000000;">3</span> rupert  admin    <span style="color: #000000;">102</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">21</span>:<span style="color: #000000;">14</span> vendor</pre></div></div>

<p>I have /wwwroot as my document WebRoot. Its running cf, php and mapserv (cgi-bin). Since I want to mix it with rails development, I&#8217;ll just make a rails subdirectory. Inside the rails subdirectory, I can create symbolic links to my rails applications located in my projects directory. This way, rails configuration is not exposed from Apache.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>wwwroot
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> rails
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</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>projects<span style="color: #000000; font-weight: bold;">/</span>rails<span style="color: #000000; font-weight: bold;">/</span>travelsiteph<span style="color: #000000; font-weight: bold;">/</span>public travelsiteph
&nbsp;
$ <span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-la</span>
total <span style="color: #000000;">8</span>
drwxr-xr-x   <span style="color: #000000;">3</span> rupert  admin   <span style="color: #000000;">102</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">14</span>:09 .
drwxrwxr-x  <span style="color: #000000;">60</span> root    admin  <span style="color: #000000;">2040</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">14</span>:08 ..
lrwxr-xr-x   <span style="color: #000000;">1</span> rupert  admin    <span style="color: #000000;">42</span>  <span style="color: #000000;">2</span> Sep <span style="color: #000000;">14</span>:09 travelsiteph -<span style="color: #000000; font-weight: bold;">&gt;</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>projects<span style="color: #000000; font-weight: bold;">/</span>rails<span style="color: #000000; font-weight: bold;">/</span>travelsiteph<span style="color: #000000; font-weight: bold;">/</span>public</pre></div></div>

<p>5. Restart Apache to take the new configuration</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: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>StartupItems<span style="color: #000000; font-weight: bold;">/</span>Apache2<span style="color: #000000; font-weight: bold;">/</span>Apache2 restart</pre></div></div>

<p>6. Open http://127.0.0.1/rails/travelsiteph/</p>
<p><em>But for development purposes, it is better to use http://127.0.0.1:3000/ to see immediately any changes in code.</em> </p>
<p><img src="/wordpress/wp-content/uploads/2009/09/rails.png" alt="rails.png" border="0" width="150" height="108" /></p>
<p><strong>Part 2: Rails Development</strong><br />
MySQL Prerequisites:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">GRANT</span> <span style="color: #993333; font-weight: bold;">ALL</span> PRIVILEGES <span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #66cc66;">*.*</span> <span style="color: #993333; font-weight: bold;">TO</span> rupert@<span style="color: #ff0000;">'%'</span> <span style="color: #993333; font-weight: bold;">IDENTIFIED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">'*************'</span> <span style="color: #993333; font-weight: bold;">WITH</span> <span style="color: #993333; font-weight: bold;">GRANT</span> <span style="color: #993333; font-weight: bold;">OPTION</span>;
$ mysql <span style="color: #66cc66;">-</span>u rupert <span style="color: #66cc66;">-</span>p</pre></div></div>

<p>1. Create three databases:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">DATABASE</span> travelsiteph_development;
Query OK<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span> row affected <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0.00</span> sec<span style="color: #66cc66;">&#41;</span>
&nbsp;
mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">DATABASE</span> travelsiteph_test;
Query OK<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span> row affected <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0.00</span> sec<span style="color: #66cc66;">&#41;</span>
&nbsp;
mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">DATABASE</span> travelsiteph_deployment;
Query OK<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span> row affected <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0.00</span> sec<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>2. Launch Textmate</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</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>projects<span style="color: #000000; font-weight: bold;">/</span>rails<span style="color: #000000; font-weight: bold;">/</span>travelsiteph
mate .</pre></div></div>

<p>3. Edit database.yml</p>

<div class="wp_syntax"><div class="code"><pre class="yml" style="font-family:monospace;">development:
  adapter: mysql
  database: travelsiteph_development
  username: root
  password: xxxxxxx
  host: localhost
&nbsp;
test:
  adapter: mysql
  database: travelsiteph_test
  username: root
  password: xxxxxxx
  host: localhost
&nbsp;
production:
  adapter: mysql
  database: travelsiteph_deployment
  username: root
  password: xxxxxxx
  host: localhost</pre></div></div>

<p>4. Generate a Poi model. <em>The model should be capitalized and singular.</em></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ ruby script<span style="color: #000000; font-weight: bold;">/</span>generate model Poi
      exists  app<span style="color: #000000; font-weight: bold;">/</span>models<span style="color: #000000; font-weight: bold;">/</span>
      exists  test<span style="color: #000000; font-weight: bold;">/</span>unit<span style="color: #000000; font-weight: bold;">/</span>
      exists  test<span style="color: #000000; font-weight: bold;">/</span>fixtures<span style="color: #000000; font-weight: bold;">/</span>
      create  app<span style="color: #000000; font-weight: bold;">/</span>models<span style="color: #000000; font-weight: bold;">/</span>poi.rb
      create  test<span style="color: #000000; font-weight: bold;">/</span>unit<span style="color: #000000; font-weight: bold;">/</span>poi_test.rb
      create  test<span style="color: #000000; font-weight: bold;">/</span>fixtures<span style="color: #000000; font-weight: bold;">/</span>pois.yml
      create  db<span style="color: #000000; font-weight: bold;">/</span>migrate
      create  db<span style="color: #000000; font-weight: bold;">/</span>migrate<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">20090902111538</span>_create_pois.rb</pre></div></div>

<p>5. Now let&#8217;s create the database table for Poi using migrations.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Poi <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Migration</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">up</span>
    create_table <span style="color:#ff3333; font-weight:bold;">:pois</span>, <span style="color:#ff3333; font-weight:bold;">:id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:poi_id</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>t<span style="color:#006600; font-weight:bold;">|</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:name</span>, <span style="color:#ff3333; font-weight:bold;">:string</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:full_address</span>, <span style="color:#ff3333; font-weight:bold;">:string</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:location</span>, <span style="color:#ff3333; font-weight:bold;">:string</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:get_there</span>, <span style="color:#ff3333; font-weight:bold;">:string</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:short_description</span>, <span style="color:#ff3333; font-weight:bold;">:string</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:full_description</span>, <span style="color:#ff3333; font-weight:bold;">:text</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:other_info</span>, <span style="color:#ff3333; font-weight:bold;">:text</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:tel_no</span>, <span style="color:#ff3333; font-weight:bold;">:string</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:fax_no</span>, <span style="color:#ff3333; font-weight:bold;">:string</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:mobile_no</span>, <span style="color:#ff3333; font-weight:bold;">:string</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:email</span>, <span style="color:#ff3333; font-weight:bold;">:string</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:website</span>, <span style="color:#ff3333; font-weight:bold;">:string</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:other_contact_details</span>, <span style="color:#ff3333; font-weight:bold;">:text</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:longitude</span>, <span style="color:#ff3333; font-weight:bold;">:decimal</span>, <span style="color:#ff3333; font-weight:bold;">:precision</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">10</span>, <span style="color:#ff3333; font-weight:bold;">:scale</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">7</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:latitude</span>, <span style="color:#ff3333; font-weight:bold;">:decimal</span>, <span style="color:#ff3333; font-weight:bold;">:precision</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">10</span>, <span style="color:#ff3333; font-weight:bold;">:scale</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">7</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:created_at</span>, <span style="color:#ff3333; font-weight:bold;">:timestamp</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:updated_at</span>, <span style="color:#ff3333; font-weight:bold;">:timestamp</span>
      t.<span style="color:#9900CC;">timestamps</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">down</span>
    drop_table <span style="color:#ff3333; font-weight:bold;">:pois</span>
  <span style="color:#9966CC; font-weight:bold;">end</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;">$ rake db:migrate
<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">in</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>projects<span style="color: #000000; font-weight: bold;">/</span>rails<span style="color: #000000; font-weight: bold;">/</span>travelsiteph<span style="color: #7a0874; font-weight: bold;">&#41;</span>
==  CreatePois: migrating =========================================
<span style="color: #660033;">--</span> create_table<span style="color: #7a0874; font-weight: bold;">&#40;</span>:point_of_interests, <span style="color: #7a0874; font-weight: bold;">&#123;</span>:<span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">id</span></span>=<span style="color: #000000; font-weight: bold;">&gt;</span>:poi_id<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
   -<span style="color: #000000; font-weight: bold;">&gt;</span> 0.0353s
==  CreatePois: migrated <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.0362s<span style="color: #7a0874; font-weight: bold;">&#41;</span> ================================</pre></div></div>

<p>6. Generate a Poi controller.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ script<span style="color: #000000; font-weight: bold;">/</span>generate controller Poi
      exists  app<span style="color: #000000; font-weight: bold;">/</span>controllers<span style="color: #000000; font-weight: bold;">/</span>
      exists  app<span style="color: #000000; font-weight: bold;">/</span>helpers<span style="color: #000000; font-weight: bold;">/</span>
      create  app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>poi
      create  test<span style="color: #000000; font-weight: bold;">/</span>functional<span style="color: #000000; font-weight: bold;">/</span>
      create  test<span style="color: #000000; font-weight: bold;">/</span>unit<span style="color: #000000; font-weight: bold;">/</span>helpers<span style="color: #000000; font-weight: bold;">/</span>
      create  app<span style="color: #000000; font-weight: bold;">/</span>controllers<span style="color: #000000; font-weight: bold;">/</span>poi_controller.rb
      create  test<span style="color: #000000; font-weight: bold;">/</span>functional<span style="color: #000000; font-weight: bold;">/</span>poi_controller_test.rb
      create  app<span style="color: #000000; font-weight: bold;">/</span>helpers<span style="color: #000000; font-weight: bold;">/</span>poi_helper.rb
      create  test<span style="color: #000000; font-weight: bold;">/</span>unit<span style="color: #000000; font-weight: bold;">/</span>helpers<span style="color: #000000; font-weight: bold;">/</span>poi_helper_test.rb</pre></div></div>

<p>7. Add a <em>list</em> function to Poi 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> PoiController <span style="color:#006600; font-weight:bold;">&lt;</span> ApplicationController
  <span style="color:#9966CC; font-weight:bold;">def</span> list
    <span style="color:#0066ff; font-weight:bold;">@pois</span> = Poi.<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:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>8. Lets test. Open a browser and point to http://127.0.0.1:3000/travelsiteph/poi/list</p>

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

<p>9. Now create the view <em>list.rhtml</em> in <em>views/poi/</em></p>

<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@pois</span>.<span style="color:#9900CC;">blank</span>? <span style="color:#006600; font-weight:bold;">%&gt;</span>
&nbsp;
	&lt;p&gt;There are currently no pois in the system. &lt;/p&gt;
&nbsp;
<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>
&nbsp;
	&lt;p&gt;These are the pois in the system: &lt;/p&gt;
&nbsp;
	&lt;ul&gt;
		<span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#0066ff; font-weight:bold;">@pois</span>.<span style="color:#5A0A0A; font-weight:bold;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>poi<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
			&lt;li&gt;<span style="color:#006600; font-weight:bold;">&lt;%</span>= <span style="color:#5A0A0A; font-weight:bold;">link_to</span> poi.<span style="color:#9900CC;">name</span>, <span style="color:#006600; font-weight:bold;">&#123;</span>:action <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'show'</span>, <span style="color:#ff3333; font-weight:bold;">:id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> poi.<span style="color:#9900CC;">id</span><span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#006600; font-weight:bold;">-%&gt;</span>&lt;/li&gt;
		<span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
	&lt;/ul&gt;
&nbsp;
<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><strong>Part 3: Deploying</strong><br />
1. set RAILS_ENV to production</p>
<pre>export RAILS_ENV=production</pre>
<p>2. Make sure to populate the database in production mode, run rake db:migrate</p>
<p>3. Capistrano</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">set <span style="color:#ff3333; font-weight:bold;">:port</span>, <span style="color:#006666;">2210</span>
set <span style="color:#ff3333; font-weight:bold;">:application</span>, <span style="color:#996600;">&quot;halalan2010&quot;</span>
<span style="color:#008000; font-style:italic;">#set :repository,  &quot;svn+ssh://2rmobile.com/data/repos/web/rails/halalan2010/&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:repository</span>,  <span style="color:#996600;">&quot;http://2rmobile.com/repos/web/rails/halalan2010/&quot;</span>
&nbsp;
set <span style="color:#ff3333; font-weight:bold;">:scm</span>, <span style="color:#ff3333; font-weight:bold;">:subversion</span>
set <span style="color:#ff3333; font-weight:bold;">:scm_username</span>, <span style="color:#996600;">'rupert'</span>
set <span style="color:#ff3333; font-weight:bold;">:scm_password</span>, <span style="color:#CC0066; font-weight:bold;">proc</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#6666ff; font-weight:bold;">Capistrano::CLI</span>.<span style="color:#9900CC;">password_prompt</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'SVN pass:'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#008000; font-style:italic;"># Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`</span>
&nbsp;
role <span style="color:#ff3333; font-weight:bold;">:web</span>, <span style="color:#996600;">&quot;2rmobile.com&quot;</span> <span style="color:#008000; font-style:italic;"># IP Your HTTP server, Apache/etc</span>
role <span style="color:#ff3333; font-weight:bold;">:app</span>, <span style="color:#996600;">&quot;2rmobile.com&quot;</span> <span style="color:#008000; font-style:italic;"># This may be the same as your `Web` server</span>
role <span style="color:#ff3333; font-weight:bold;">:db</span>,  <span style="color:#996600;">&quot;2rmobile.com&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:primary</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span> <span style="color:#008000; font-style:italic;"># This is where Rails migrations will run</span>
<span style="color:#008000; font-style:italic;">#role :db,  &quot;your slave db-server here&quot;</span>
&nbsp;
set <span style="color:#ff3333; font-weight:bold;">:user</span>,  <span style="color:#996600;">&quot;rupert&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:runner</span>, <span style="color:#996600;">&quot;rupert&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:deploy_to</span>, <span style="color:#996600;">&quot;/opt/rails/#{application}&quot;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># If you are using Passenger mod_rails uncomment this:</span>
<span style="color:#008000; font-style:italic;"># if you're still using the script/reapear helper you will need</span>
<span style="color:#008000; font-style:italic;"># these http://github.com/rails/irs_process_scripts</span>
&nbsp;
namespace <span style="color:#ff3333; font-weight:bold;">:deploy</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  task <span style="color:#ff3333; font-weight:bold;">:start</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    run <span style="color:#996600;">&quot;/etc/init.d/apache2 start&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
  task <span style="color:#ff3333; font-weight:bold;">:stop</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    run <span style="color:#996600;">&quot;/etc/init.d/apache2 stop&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
  task <span style="color:#ff3333; font-weight:bold;">:restart</span>, <span style="color:#ff3333; font-weight:bold;">:roles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:app</span>, <span style="color:#ff3333; font-weight:bold;">:except</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;">:no_release</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span> <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
     run <span style="color:#996600;">&quot;#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
  task <span style="color:#ff3333; font-weight:bold;">:production</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    run <span style="color:#996600;">&quot;export RAILS_ENV=production&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
namespace <span style="color:#ff3333; font-weight:bold;">:db</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  task <span style="color:#ff3333; font-weight:bold;">:seed</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    run <span style="color:#996600;">&quot;cd #{deploy_to}/current &amp;&amp; RAILS_ENV=production rake db:seed&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
  task <span style="color:#ff3333; font-weight:bold;">:populate</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    run <span style="color:#996600;">&quot;cd #{deploy_to}/current &amp;&amp; RAILS_ENV=production rake db:populate&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Capistrano commands I normally use:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">#on local
#cap deploy:setup
&nbsp;
#on remote and change owner and permissions of project
sudo chown -Rf rupert:root halalan2010
&nbsp;
#on local
#cap deploy
#cap db:seed
#cap db:populate</pre></div></div>

<p><strong>Part 4: Miscellaneous</strong></p>
<p><strong>1. Get a description or rake commands</strong></p>
<pre>rake -D db</pre>
<p><strong>2. How to populate the database in production mode?</strong></p>

<div class="wp_syntax"><div class="code"><pre class="console" style="font-family:monospace;">rupert:halalan2010 rupert$ export RAILS_ENV=production
rupert:halalan2010 rupert$ rake db:migrate
(in /Users/rupert/projects/rails/halalan2010)
==  CreateDatabase: migrating =================================================
-- create_table(:candidates)
   -&gt; 0.0036s
-- create_table(:voters)
   -&gt; 0.0031s
-- create_table(:votes)
   -&gt; 0.0027s
==  CreateDatabase: migrated (0.0100s) ========================================</pre></div></div>

<p><a href="http://blog.airbladesoftware.com/2009/4/10/avoid-typing-rails_env-all-the-time">http://blog.airbladesoftware.com/2009/4/10/avoid-typing-rails_env-all-the-time</a></p>
<p><strong>3. Uninstall specific gem version</strong></p>
<pre>
gem uninstall activesupport -v 2.2.2
</pre>
<p><strong>4 Add a source to gem</strong></p>
<pre>
rupert:rails rupert$ sudo gem sources -a http://gems.github.com
http://gems.github.com added to sources
</pre>
<p><strong>5. Adding a rails project in svn</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#create a remote dir</span>
<span style="color: #c20cb9; font-weight: bold;">svn</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.2rmobile.com<span style="color: #000000; font-weight: bold;">/</span>repos<span style="color: #000000; font-weight: bold;">/</span>web<span style="color: #000000; font-weight: bold;">/</span>rails<span style="color: #000000; font-weight: bold;">/</span>virginmobilechecker
&nbsp;
<span style="color: #666666; font-style: italic;">#checkout and copy all files</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>projects<span style="color: #000000; font-weight: bold;">/</span>rails
<span style="color: #c20cb9; font-weight: bold;">mv</span> virginmobilechecker virginmobilechecker_old
<span style="color: #c20cb9; font-weight: bold;">svn</span> <span style="color: #c20cb9; font-weight: bold;">co</span> <span style="color: #ff0000;">&quot;svn+ssh://2rmobile.com/data/repos/web/rails/virginmobilechecker&quot;</span> virginmobilechecker
<span style="color: #c20cb9; font-weight: bold;">mv</span> virginmobilechecker_old<span style="color: #000000; font-weight: bold;">/*</span> virginmobilechecker<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> virginmobilechecker
<span style="color: #c20cb9; font-weight: bold;">svn</span> add <span style="color: #000000; font-weight: bold;">*</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#ignoring log files</span>
<span style="color: #c20cb9; font-weight: bold;">svn</span> revert log<span style="color: #000000; font-weight: bold;">/*</span>
<span style="color: #c20cb9; font-weight: bold;">svn</span> propset <span style="color: #c20cb9; font-weight: bold;">svn</span>:ignore <span style="color: #ff0000;">&quot;*.log&quot;</span> log
<span style="color: #c20cb9; font-weight: bold;">svn</span> propset <span style="color: #c20cb9; font-weight: bold;">svn</span>:ignore <span style="color: #ff0000;">&quot;*&quot;</span> tmp
<span style="color: #c20cb9; font-weight: bold;">svn</span> propset <span style="color: #c20cb9; font-weight: bold;">svn</span>:ignore <span style="color: #ff0000;">&quot;*&quot;</span> doc
&nbsp;
<span style="color: #666666; font-style: italic;">#commit the files</span>
<span style="color: #c20cb9; font-weight: bold;">svn</span> commit <span style="color: #660033;">-m</span> <span style="color: #ff0000;">&quot;first commit&quot;</span> <span style="color: #000000; font-weight: bold;">*</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2010/02/ruby-on-rails-quickstart-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TextMate CheatSheet (Updated)</title>
		<link>/wordpress/2009/08/textmate-cheatsheet-2/</link>
		<comments>/wordpress/2009/08/textmate-cheatsheet-2/#comments</comments>
		<pubDate>Sun, 02 Aug 2009 03:10:12 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[osx]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[textmate]]></category>

		<guid isPermaLink="false">/wordpress/?p=808</guid>
		<description><![CDATA[Shortcuts Ruby: --------------------------------- :key =&#62; &#34;value&#34; - : + tab &#160; Navigate: --------------------------------- go to file - cmd - t tab to file (left&#124;right) - opt + cmd + (left arrow&#124;right arrow) select bundle item - ctrl + cmd + t navigate (from controller to view) - opt + cmd + down arrow show methods [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Shortcuts</strong></p>

<div class="wp_syntax"><div class="code"><pre class="textmate" style="font-family:monospace;">Ruby:
---------------------------------
:key =&gt; &quot;value&quot; - : + tab
&nbsp;
Navigate:
---------------------------------
go to file - cmd - t
tab to file (left|right) - opt + cmd + (left arrow|right arrow)
select bundle item - ctrl + cmd + t
navigate (from controller to view) - opt + cmd + down arrow
show methods - shift + cmd + t
&nbsp;
Views:
---------------------------------
create partial - ctrl + shift + H
render partial (object|collection|locals) - r + p + (o|c|l)
inserting an erb tag &lt;%=  %&gt; or &lt;% %&gt; - ctrl + shift + . (cycle)
code completion, &lt;h3&gt;foo&lt;/h3&gt; - opt + cmd + .
&nbsp;
2RMobile Snippets:
---------------------------------
&lt;% objects.each do |object| %&gt;		2rmloope
	&lt;%= object. %&gt;
&lt;% end %&gt;</pre></div></div>

<p><strong>* <a href="http://www.devdaily.com/blog/post/mac-os-x/how-to-move-textmate-project-drawer-left-right-side/">Make the project drawer appear on the left or right.</a><br />
</strong></p>
<p>From the menubar select View, then Hide Project Drawer.</p>
<p>Move your TextMate editor window over to the left side of the screen so the project gutter won&#8217;t have enough room to open up on that side. (You can move the window all the way to the left if you want, but you don&#8217;t need to go that far.)</p>
<p>Select View, then Show Project Drawer, and the drawer will now open on the right side of your TextMate editor.</p>
<p><strong>* Plugins directory is located at</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">1. <span style="color: #000000; font-weight: bold;">/</span>Applications<span style="color: #000000; font-weight: bold;">/</span>TextMate.app<span style="color: #000000; font-weight: bold;">/</span>Contents<span style="color: #000000; font-weight: bold;">/</span>PlugIns<span style="color: #000000; font-weight: bold;">/</span>
2. <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>Library<span style="color: #000000; font-weight: bold;">/</span>Application Support<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p><a href="http://manual.macromates.com/en/bundles#support_folder">http://manual.macromates.com/en/bundles#support_folder</a></p>
<p><strong>* Installing a bundle.</strong><br />
RubyOnRails Bundle: <a href="https://github.com/drnic/ruby-on-rails-tmbundle">https://github.com/drnic/ruby-on-rails-tmbundle</a><br />
RSpec Bundle: <a href="https://github.com/rspec/rspec-tmbundle">https://github.com/rspec/rspec-tmbundle</a><br />
Cucumber Bundle: <a href="https://github.com/aslakhellesoy/cucumber-tmbundle">https://github.com/aslakhellesoy/cucumber-tmbundle</a></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> ~<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Application\ Support<span style="color: #000000; font-weight: bold;">/</span>TextMate<span style="color: #000000; font-weight: bold;">/</span>Bundles
<span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Application\ Support<span style="color: #000000; font-weight: bold;">/</span>TextMate<span style="color: #000000; font-weight: bold;">/</span>Bundles
git clone git:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>drnic<span style="color: #000000; font-weight: bold;">/</span>ruby-on-rails-tmbundle.git <span style="color: #ff0000;">&quot;Ruby on Rails.tmbundle&quot;</span></pre></div></div>

<p>Launch TextMate > Bundles > Bundle Editor > &#8220;Reload Bundles&#8221;</p>
<p><strong>* Identify *.html.erb to open in HTML(Rails)</strong><br />
Read <a href="http://blog.macromates.com/2007/file-type-detection-rspec-rails/<br />
">http://blog.macromates.com/2007/file-type-detection-rspec-rails/</a></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rupert:blog rupert$ defaults <span style="color: #c20cb9; font-weight: bold;">read</span> com.macromates.textmate OakLanguageFileBindings
<span style="color: #7a0874; font-weight: bold;">&#40;</span>
        <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        fileTypes =         <span style="color: #7a0874; font-weight: bold;">&#40;</span>
            txt
        <span style="color: #7a0874; font-weight: bold;">&#41;</span>;
        language = <span style="color: #ff0000;">&quot;17994EC8-6B1D-11D9-AC3A-000D93589AF6&quot;</span>;
        name = HTML;
    <span style="color: #7a0874; font-weight: bold;">&#125;</span>,
        <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        fileTypes =         <span style="color: #7a0874; font-weight: bold;">&#40;</span>
            builder,
            rb,
            erb
        <span style="color: #7a0874; font-weight: bold;">&#41;</span>;
        language = <span style="color: #ff0000;">&quot;54D6E91E-8F31-11D9-90C5-0011242E4184&quot;</span>;
        name = <span style="color: #ff0000;">&quot;Ruby on Rails&quot;</span>;
    <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #7a0874; font-weight: bold;">&#41;</span>
rupert:blog rupert$ defaults delete com.macromates.textmate OakLanguageFileBindings</pre></div></div>

<p><strong>* Identify Gemfiles in TextMate for Ruby on Rails</strong><br />
Read <a href="http://efreedom.com/Question/1-3174451/Bundler-Gemfile-Syntax-Highlight-Text-Mate">http://efreedom.com/Question/1-3174451/Bundler-Gemfile-Syntax-Highlight-Text-Mate</a></p>
<p>Include the &#8216;Gemfile&#8217; as a filetype</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">fileTypes = <span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #ff0000;">'rb'</span>, <span style="color: #ff0000;">'rxml'</span>, <span style="color: #ff0000;">'builder'</span>, <span style="color: #ff0000;">'Gemfile'</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span>;</pre></div></div>

<p><strong>* Soft Tabs and Spaces in TextMate</strong><br />
To turn on soft tabs (bottom of the window, in the tab size selector). This will insert spaces instead of tabs, so there won&#8217;t be anything to convert when it&#8217;s time to save<br />
Source: <a href="http://old.nabble.com/Convert-tabs-to-spaces-when-saving--td28891731.html">http://old.nabble.com/Convert-tabs-to-spaces-when-saving&#8211;td28891731.html</a></p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2009/08/textmate-cheatsheet-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails Note #13: RubyonRails + Oracle on Linux (i386 / x64)</title>
		<link>/wordpress/2008/12/rubyonrails-oracle-on-linux-i386-x64/</link>
		<comments>/wordpress/2008/12/rubyonrails-oracle-on-linux-i386-x64/#comments</comments>
		<pubDate>Thu, 11 Dec 2008 00:53:48 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[debian]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">/wordpress/?p=310</guid>
		<description><![CDATA[In summary, install Oracle Instant Client and try to run sqlplus. If sqlplus connects to the oracle sid then go ahead and install the rails adapters for oracle. What is important to note here, is to install the oracle-instantclient for the architecture of your machine.. I have tested this on Debian Lenny (i386) and CentOS5 [...]]]></description>
			<content:encoded><![CDATA[<p>In summary, install Oracle Instant Client and try to run sqlplus. If sqlplus connects to the oracle sid then go ahead and install the rails adapters for oracle. <strong>What is important to note here, is to install the oracle-instantclient for the architecture of your machine.</strong>. I have tested this on Debian Lenny (i386) and CentOS5 (x64)</p>
<p>1. Download from <a href="http://www.oracle.com/technology/software/tech/oci/instantclient/">http://www.oracle.com/technology/software/tech/oci/instantclient/</a></p>
<p>a. oracle-instantclient-basic-10.2.0.4-1.i386<br />
b. oracle-instantclient-devel-10.2.0.4-1.i386<br />
c. oracle-instantclient-sqlplus-10.2.0.4-1.i386</p>
<p>2. Unzip everything to /opt/oracle/instantclient . You should have something like the ff:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>csapp1 instantclient<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># ls -la</span>
total <span style="color: #000000;">102704</span>
drwxr-xr-x <span style="color: #000000;">3</span> root root     <span style="color: #000000;">4096</span> Dec <span style="color: #000000;">10</span> <span style="color: #000000;">21</span>:<span style="color: #000000;">54</span> .
drwxr-xr-x <span style="color: #000000;">3</span> root root     <span style="color: #000000;">4096</span> Dec <span style="color: #000000;">10</span> <span style="color: #000000;">22</span>:03 ..
<span style="color: #660033;">-rw-r--r--</span> <span style="color: #000000;">1</span> root root      <span style="color: #000000;">228</span> Dec <span style="color: #000000;">10</span> <span style="color: #000000;">21</span>:<span style="color: #000000;">52</span> BASIC_README
<span style="color: #660033;">-r--r--r--</span> <span style="color: #000000;">1</span> root root  <span style="color: #000000;">1609607</span> Dec <span style="color: #000000;">10</span> <span style="color: #000000;">21</span>:<span style="color: #000000;">52</span> classes12.jar
<span style="color: #660033;">-rwxr-xr-x</span> <span style="color: #000000;">1</span> root root    <span style="color: #000000;">67542</span> Dec <span style="color: #000000;">10</span> <span style="color: #000000;">21</span>:<span style="color: #000000;">52</span> genezi
<span style="color: #660033;">-r--r--r--</span> <span style="color: #000000;">1</span> root root     <span style="color: #000000;">1525</span> Dec <span style="color: #000000;">10</span> <span style="color: #000000;">21</span>:<span style="color: #000000;">52</span> glogin.sql
lrwxrwxrwx <span style="color: #000000;">1</span> root root       <span style="color: #000000;">17</span> Dec <span style="color: #000000;">10</span> <span style="color: #000000;">21</span>:<span style="color: #000000;">54</span> libclntsh.so -<span style="color: #000000; font-weight: bold;">&gt;</span> libclntsh.so.10.1
<span style="color: #660033;">-rwxr-xr-x</span> <span style="color: #000000;">1</span> root root <span style="color: #000000;">21038613</span> Dec <span style="color: #000000;">10</span> <span style="color: #000000;">21</span>:<span style="color: #000000;">52</span> libclntsh.so.10.1
<span style="color: #660033;">-r-xr-xr-x</span> <span style="color: #000000;">1</span> root root  <span style="color: #000000;">3796601</span> Dec <span style="color: #000000;">10</span> <span style="color: #000000;">21</span>:<span style="color: #000000;">52</span> libnnz10.so
<span style="color: #660033;">-rwxr-xr-x</span> <span style="color: #000000;">1</span> root root  <span style="color: #000000;">1664116</span> Dec <span style="color: #000000;">10</span> <span style="color: #000000;">21</span>:<span style="color: #000000;">52</span> libocci.so.10.1
<span style="color: #660033;">-rwxr-xr-x</span> <span style="color: #000000;">1</span> root root <span style="color: #000000;">72674185</span> Dec <span style="color: #000000;">10</span> <span style="color: #000000;">21</span>:<span style="color: #000000;">52</span> libociei.so
<span style="color: #660033;">-r-xr-xr-x</span> <span style="color: #000000;">1</span> root root   <span style="color: #000000;">138033</span> Dec <span style="color: #000000;">10</span> <span style="color: #000000;">21</span>:<span style="color: #000000;">52</span> libocijdbc10.so
<span style="color: #660033;">-r-xr-xr-x</span> <span style="color: #000000;">1</span> root root  <span style="color: #000000;">1435561</span> Dec <span style="color: #000000;">10</span> <span style="color: #000000;">21</span>:<span style="color: #000000;">52</span> libsqlplusic.so
<span style="color: #660033;">-r-xr-xr-x</span> <span style="color: #000000;">1</span> root root   <span style="color: #000000;">997409</span> Dec <span style="color: #000000;">10</span> <span style="color: #000000;">21</span>:<span style="color: #000000;">52</span> libsqlplus.so
<span style="color: #660033;">-r--r--r--</span> <span style="color: #000000;">1</span> root root  <span style="color: #000000;">1555682</span> Dec <span style="color: #000000;">10</span> <span style="color: #000000;">21</span>:<span style="color: #000000;">52</span> ojdbc14.jar
drwxr-xr-x <span style="color: #000000;">4</span> root root     <span style="color: #000000;">4096</span> Dec <span style="color: #000000;">10</span> <span style="color: #000000;">21</span>:<span style="color: #000000;">52</span> sdk
<span style="color: #660033;">-r-xr-xr-x</span> <span style="color: #000000;">1</span> root root     <span style="color: #000000;">7773</span> Dec <span style="color: #000000;">10</span> <span style="color: #000000;">21</span>:<span style="color: #000000;">52</span> sqlplus
<span style="color: #660033;">-rw-r--r--</span> <span style="color: #000000;">1</span> root root      <span style="color: #000000;">232</span> Dec <span style="color: #000000;">10</span> <span style="color: #000000;">21</span>:<span style="color: #000000;">52</span> SQLPLUS_README
<span style="color: #660033;">-rw-r--r--</span> <span style="color: #000000;">1</span> root root      <span style="color: #000000;">516</span> Dec <span style="color: #000000;">10</span> <span style="color: #000000;">21</span>:<span style="color: #000000;">53</span> tnsnames.ora
<span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>csapp1 instantclient<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;">#</span></pre></div></div>

<p>3. Make a symbolic link for libclntsh.so.10.1 as shown above.</p>
<p>4. Create the Oracle Environment variables</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">ORACLE_HOME</span>=<span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>oracle<span style="color: #000000; font-weight: bold;">/</span>instantclient
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">TNS_ADMIN</span>=<span style="color: #007800;">$ORACLE_HOME</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">LD_LIBRARY_PATH</span>=<span style="color: #007800;">$ORACLE_HOME</span>:<span style="color: #007800;">$LD_LIBRARY_PATH</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">DYLD_LIBRARY_PATH</span>=<span style="color: #007800;">$ORACLE_HOME</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PATH</span>=<span style="color: #007800;">$PATH</span>:<span style="color: #007800;">$ORACLE_HOME</span></pre></div></div>

<p>5. At this point, you should have oracle-instantclient properly installed. You can test by running <strong>sqlplus</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>csapp1 instantclient<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># sqlplus</span>
&nbsp;
SQL<span style="color: #000000; font-weight: bold;">*</span>Plus: Release 10.2.0.4.0 - Production on Thu Dec <span style="color: #000000;">11</span> <span style="color: #000000;">11</span>:<span style="color: #000000;">47</span>:<span style="color: #000000;">40</span> <span style="color: #000000;">2008</span>
&nbsp;
Copyright <span style="color: #7a0874; font-weight: bold;">&#40;</span>c<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000;">1982</span>, <span style="color: #000000;">2007</span>, Oracle.  All Rights Reserved.</pre></div></div>

<p>NOTE: Sometimes you will get a SEGMENTATION FAULT. If so, try to open a new shell with the environment variables loaded and do an <strong>sqlplus</strong> in a directory which is not <em>/opt/oracle/instantclient</em>.</p>
<p>6. Install the oracle adapter for rails</p>
<p>7. gem install ruby-oci8</p>
<p>8. gem install oracle_enhanced-adapter &#8211;source=&#8221;http://gems.rubyonrails.org/&#8221;</p>
<p>activerecord-oracle-adapter (1.0.0.9250)<br />
activerecord-oracle_enhanced-adapter (1.1.8)</p>
<p>NOTE: Try to look for the latest gems, the source above is at the time of this writing so it might change.</p>
<p>9. Test using <strong>irb</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>csapp1 instantclient<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># irb</span>
irb<span style="color: #7a0874; font-weight: bold;">&#40;</span>main<span style="color: #7a0874; font-weight: bold;">&#41;</span>:001:<span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">&gt;</span> require <span style="color: #ff0000;">'rubygems'</span>
=<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #c20cb9; font-weight: bold;">true</span>
irb<span style="color: #7a0874; font-weight: bold;">&#40;</span>main<span style="color: #7a0874; font-weight: bold;">&#41;</span>:002:<span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">&gt;</span> require <span style="color: #ff0000;">'oci8'</span>
=<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #c20cb9; font-weight: bold;">true</span>
irb<span style="color: #7a0874; font-weight: bold;">&#40;</span>main<span style="color: #7a0874; font-weight: bold;">&#41;</span>:003:<span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2008/12/rubyonrails-oracle-on-linux-i386-x64/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails Note #12: Oracle on Intel Mac</title>
		<link>/wordpress/2008/12/ruby-and-rails-oracle-on-intel-mac/</link>
		<comments>/wordpress/2008/12/ruby-and-rails-oracle-on-intel-mac/#comments</comments>
		<pubDate>Fri, 05 Dec 2008 07:52:28 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[mac]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">/wordpress/?p=307</guid>
		<description><![CDATA[1. Read http://www.foliosus.com/2008/05/05/connecting-ruby-on-rails-to-oracle-on-an-intel-mac-in-leopard-take-2/ 2. Install Oracle Instant Client on Mac. a. Instant Client Package &#8211; Basic: All files required to run OCI, OCCI, and JDBC-OCI applications - instantclient-basic-macosx-10.2.0.4.0.zip (34,020,719 bytes) b. *Instant Client Package &#8211; SDK: Additional header files and an example makefile for developing Oracle applications with Instant Client instantclient-sdk-macosx-10.2.0.4.0.zip (603,493 bytes) OR download [...]]]></description>
			<content:encoded><![CDATA[<p>1.  Read <a href="http://www.foliosus.com/2008/05/05/connecting-ruby-on-rails-to-oracle-on-an-intel-mac-in-leopard-take-2/">http://www.foliosus.com/2008/05/05/connecting-ruby-on-rails-to-oracle-on-an-intel-mac-in-leopard-take-2/</a></p>
<p>2. Install <a href="http://www.oracle.com/technology/software/tech/oci/instantclient/htdocs/intel_macsoft.html">Oracle Instant Client on Mac</a>. </p>
<p>a. Instant Client Package &#8211; Basic: All files required to run OCI, OCCI, and JDBC-OCI applications<br />
- instantclient-basic-macosx-10.2.0.4.0.zip (34,020,719 bytes)</p>
<p>b. *Instant Client Package &#8211; SDK: Additional header files and an example makefile for developing Oracle applications with Instant Client<br />
instantclient-sdk-macosx-10.2.0.4.0.zip (603,493 bytes) </p>
<p>OR download the <a href="/installers/oracle/10.2.0.4.zip">whole bundle (10.2.0.4.zip)</a> with sqlplus installed from my installers.</p>
<p>3. Put this on your sudo vim ~/.bash_profile.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">ORACLE_HOME</span>=<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Oracle<span style="color: #000000; font-weight: bold;">/</span>instantclient<span style="color: #000000; font-weight: bold;">/</span>10.2.0.4
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">TNS_ADMIN</span>=<span style="color: #007800;">$ORACLE_HOME</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">LD_LIBRARY_PATH</span>=<span style="color: #007800;">$ORACLE_HOME</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">DYLD_LIBRARY_PATH</span>=<span style="color: #007800;">$ORACLE_HOME</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PATH</span>=<span style="color: #007800;">$PATH</span>:<span style="color: #007800;">$ORACLE_HOME</span></pre></div></div>

<p>4. Make a symbolic link</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Oracle<span style="color: #000000; font-weight: bold;">/</span>instantclient<span style="color: #000000; font-weight: bold;">/</span>10.2.0.4
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> libclntsh.dylib.10.1 libclntsh.dylib</pre></div></div>

<p>5. Go to /Library/Oracle/instantclient/10.2.0.4 and edit tnsnames.ora. Point the Oracle SID to the IP where you installed Oracle.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.155)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )   
  )
&nbsp;
&nbsp;
ORCL_2_11 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.11)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )   
  )</pre></div></div>

<p>6. Install the oracle-adapter for rails</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> activerecord-oracle-adapter <span style="color: #660033;">--source</span> http:<span style="color: #000000; font-weight: bold;">//</span>gems.rubyonrails.org</pre></div></div>

<p>7. In your database.yml file</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">development:
  adapter: oracle
  database: orcl
  username: youzhu_mobile_dev
  password: your_password</pre></div></div>

<p>or browse the contents of a sample rails project <a href="/wordpress/wp-content/uploads/2008/12/youzhumobiletar.gz" title="youzhumobile.tar.gz">youzhumobile.tar.gz</a> </p>
<p>8. If you ever encounter an <strong>encoding problem</strong>, then we need to set the NLS_LANG environment variable before running <em>script/server</em>.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># export NLS_LANG=American_America.UTF8</span>
<span style="color: #666666; font-style: italic;"># script/server</span></pre></div></div>

<p>or I prefer setting it in the environment.rb</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#6666ff; font-weight:bold;">Rails::Initializer</span>.<span style="color:#9900CC;">run</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>config<span style="color:#006600; font-weight:bold;">|</span>
  ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'NLS_LANG'</span><span style="color:#006600; font-weight:bold;">&#93;</span>=<span style="color:#996600;">'American_America.UTF8'</span>
  <span style="color:#008000; font-style:italic;"># Settings in config/environments/* take precedence over those specified here.</span></pre></div></div>

<p>Note: <a href="/wordpress/?p=228">If you don&#8217;t know your database encoding, then read this post.</a></p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2008/12/ruby-and-rails-oracle-on-intel-mac/feed/</wfw:commentRss>
		<slash:comments>1</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>
		<item>
		<title>Rails Note #2: Links</title>
		<link>/wordpress/2008/11/ruby-on-rails-links/</link>
		<comments>/wordpress/2008/11/ruby-on-rails-links/#comments</comments>
		<pubDate>Sat, 01 Nov 2008 20:52:04 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">/wordpress/?p=278</guid>
		<description><![CDATA[Ruby References Ruby Quick Reference http://www.zenspider.com/Languages/Ruby/QuickRef.html Rails References Downloadable Rails API with Javascript http://www.railsbrain.com/ (Preferred) Official Rails API http://api.rubyonrails.org/ GotAPI http://www.gotapi.com/html Naming Conventions RubyOnRails Naming Conventions from ITSignals http://itsignals.cascadia.com.au/?p=7 RubyOnRails.org TipSheetForBeginners http://wiki.rubyonrails.org/rails/pages/TipSheetForBeginners Tutorials AkitaOnRails: Rails 2.0 First Full Tutorial http://www.akitaonrails.com/2007/12/12/rolling-with-rails-2-0-the-first-full-tutorial Blogs AkitaOnRails http://www.akitaonrails.com Books The Ruby Way http://rubyhacker.com/]]></description>
			<content:encoded><![CDATA[<p><strong>Ruby References</strong></p>
<p>Ruby Quick Reference<br />
<a href="http://www.zenspider.com/Languages/Ruby/QuickRef.html">http://www.zenspider.com/Languages/Ruby/QuickRef.html</a></p>
<p><strong>Rails References</strong></p>
<p>Downloadable Rails API with Javascript <a href="http://www.railsbrain.com/">http://www.railsbrain.com/</a> (Preferred)</p>
<p>Official Rails API <a href="http://api.rubyonrails.org/">http://api.rubyonrails.org/</a></p>
<p>GotAPI<br />
<a href="http://www.gotapi.com/html">http://www.gotapi.com/html</a></p>
<p><strong>Naming Conventions</strong></p>
<p>RubyOnRails Naming Conventions from ITSignals<br />
<a href="http://itsignals.cascadia.com.au/?p=7">http://itsignals.cascadia.com.au/?p=7</a></p>
<p>RubyOnRails.org TipSheetForBeginners<br />
<a href="http://wiki.rubyonrails.org/rails/pages/TipSheetForBeginners">http://wiki.rubyonrails.org/rails/pages/TipSheetForBeginners</a></p>
<p><strong>Tutorials</strong></p>
<p>AkitaOnRails: Rails 2.0 First Full Tutorial<br />
<a href="http://www.akitaonrails.com/2007/12/12/rolling-with-rails-2-0-the-first-full-tutorial">http://www.akitaonrails.com/2007/12/12/rolling-with-rails-2-0-the-first-full-tutorial</a></p>
<p><strong>Blogs</strong></p>
<p>AkitaOnRails<br />
<a href="http://www.akitaonrails.com">http://www.akitaonrails.com</a></p>
<p><strong>Books</strong></p>
<p>The Ruby Way<br />
<a href="http://rubyhacker.com/">http://rubyhacker.com/</a></p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2008/11/ruby-on-rails-links/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails Note #1: Getting my feet wet in Ruby On Rails</title>
		<link>/wordpress/2008/11/getting-my-feet-wet-in-ruby-on-rails/</link>
		<comments>/wordpress/2008/11/getting-my-feet-wet-in-ruby-on-rails/#comments</comments>
		<pubDate>Sat, 01 Nov 2008 19:23:56 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">/wordpress/?p=277</guid>
		<description><![CDATA[1. Just installed Ruby and Rails on my MacOSX Leopard. The current version of rails is 1.2.6. I wanted to upgrade using gem update &#8211;system but it seems like taking forever.. So I did a manual install of ruby, rubygems then rails.. 2. The tutorial that I followed was from http://hivelogic.com/articles/2008/02/ruby-rails-leopard Installation Summary 2.1 ruby [...]]]></description>
			<content:encoded><![CDATA[<p>1.  Just installed Ruby and Rails on my MacOSX Leopard. The current version of rails is 1.2.6. I wanted to upgrade using gem update &#8211;system but it seems like taking forever.. So I did a manual install of ruby, rubygems then rails..</p>
<p>2.  The tutorial that I followed was from <a href="http://hivelogic.com/articles/2008/02/ruby-rails-leopard">http://hivelogic.com/articles/2008/02/ruby-rails-leopard</a></p>
<p>Installation Summary</p>
<p>2.1 ruby</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>ftp.ruby-lang.org<span style="color: #000000; font-weight: bold;">/</span>pub<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>ruby-1.8.6-p286.tar.gz
<span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-zxvf</span> ruby-1.8.6-p286.tar.gz
.<span style="color: #000000; font-weight: bold;">/</span>configure
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>2.2 rubygems</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>rubyforge.org<span style="color: #000000; font-weight: bold;">/</span>frs<span style="color: #000000; font-weight: bold;">/</span>download.php<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">45905</span><span style="color: #000000; font-weight: bold;">/</span>rubygems-1.3.1.tgz
<span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-zxvf</span> rubygems-1.3.1.tgz
ruby setup.rb</pre></div></div>

<p>2.3 rails</p>

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

<p>2.4 other gems</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gem <span style="color: #c20cb9; font-weight: bold;">install</span> rubygems-update
gem <span style="color: #c20cb9; font-weight: bold;">install</span> mongrel
gem <span style="color: #c20cb9; font-weight: bold;">install</span> capistrano
gem <span style="color: #c20cb9; font-weight: bold;">install</span> postgres
gem <span style="color: #c20cb9; font-weight: bold;">install</span> builder</pre></div></div>

<p>3.  Browsed the first few pages of the hilarious <a href="http://www.poignantguide.net/ruby">http://www.poignantguide.net/ruby</a></p>
<p>4. Went for a book. Found Simply Rails 2.0 on Boox24x7 and Safari. Added that to my shelf and read chapters 1 &#8211; 5 on my first night.</p>
<p>5. Was able to setup database configuration in config/database.yml using Postgres. I have yet to study how oracle works.</p>
<p>6. <strong>rake db:migrate</strong> is a convenient way of building your database schema without using SQL. Simply Rails 2.0:Chapter 5:Generating a Model introduced inserting records using <strong>script/console</strong></p>
<p>7. URL Helpers for Story Resource<br />
stories_path				/stories<br />
new_story_path			/stories/new<br />
story_path(@story) 		/stories/1<br />
edit_story_path(@story) 	/stories/1/edit</p>
<p>Remember to define the route in config/routes.rb<br />
<strong>map.resources :users, :categories</strong></p>
<p>8. Naming Conventions<br />
<img src="/wordpress/wp-content/uploads/2008/11/picture-1.png" alt="Picture 1.png" border="0" width="340" height="326" /></p>
<p>Variables &#8211; lowercase letters and words separated by underscores.<br />
i.e name, country_of_origin</p>
<p>DB Table and Column names should follow convention is always pluralised.<br />
i.e users</p>
<p>Classes and Modules &#8211; no underscores and each word is capitalized<br />
i.e User, UserCategories</p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2008/11/getting-my-feet-wet-in-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

