<?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>Peter Mac And Associates&#187; Ruby on Rails</title>
	<atom:link href="http://www.petermac.com/category/ruby-on-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.petermac.com</link>
	<description>Australian freelance programmer and website design</description>
	<lastBuildDate>Thu, 17 Nov 2011 22:50:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Installing MySQL gem on OSX 10.6</title>
		<link>http://www.petermac.com/installing-mysql-gem-on-osx-10-6/</link>
		<comments>http://www.petermac.com/installing-mysql-gem-on-osx-10-6/#comments</comments>
		<pubDate>Tue, 15 Mar 2011 11:09:03 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[GNU/Linux]]></category>
		<category><![CDATA[OSX]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.petermac.com/?p=585</guid>
		<description><![CDATA[Hopefully this will be a time saver for anyone else who goes through the following pain. I have a brand spanking new OSX 10.6 installation. I installed mysql 5.5.9-OSX10.6-X86 (because I thought everything was still i386 based&#8230;watch this space!) I installed RVM and installed ruby 1.92 under RVM control. I then do a &#8216;bundle install&#8217; [...]]]></description>
			<content:encoded><![CDATA[<p>Hopefully this will be a time saver for anyone else who goes through the following pain.</p>
<p>I have a brand spanking new OSX 10.6 installation.<br />
I installed mysql 5.5.9-OSX10.6-X86 (because I thought everything was still i386 based&#8230;watch this space!)<br />
I installed RVM and installed ruby 1.92 under RVM control.<br />
I then do a &#8216;bundle install&#8217; and it gripes about not having mysql2 gem installed. I do a manual install using the following command.</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> mysql2</div></div>
<p>and after a bit of crunching, we get to the following error:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Building native extensions. &nbsp;This could take a while...<br />
ERROR: &nbsp;Error installing mysql2:<br />
&nbsp; &nbsp; ERROR: Failed to build gem native extension.<br />
<br />
1.9.1<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>ruby.h:<span style="color: #000000;">108</span>: error: <span style="color: #c20cb9; font-weight: bold;">size</span> of array ‘ruby_check_sizeof_long’ is negative<br />
<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>peter<span style="color: #000000; font-weight: bold;">/</span>.rvm<span style="color: #000000; font-weight: bold;">/</span>rubies<span style="color: #000000; font-weight: bold;">/</span>ruby-1.9.2-p180<span style="color: #000000; font-weight: bold;">/</span>include<span style="color: #000000; font-weight: bold;">/</span>ruby-1.9.1<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>ruby.h:<span style="color: #000000;">112</span>: error: <span style="color: #c20cb9; font-weight: bold;">size</span> of array ‘ruby_check_sizeof_voidp’ is negative<br />
In <span style="color: #c20cb9; font-weight: bold;">file</span> included from <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>peter<span style="color: #000000; font-weight: bold;">/</span>.rvm<span style="color: #000000; font-weight: bold;">/</span>rubies<span style="color: #000000; font-weight: bold;">/</span>ruby-1.9.2-p180<span style="color: #000000; font-weight: bold;">/</span>include<span style="color: #000000; font-weight: bold;">/</span>ruby-1.9.1<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>intern.h:<span style="color: #000000;">29</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;from <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>peter<span style="color: #000000; font-weight: bold;">/</span>.rvm<span style="color: #000000; font-weight: bold;">/</span>rubies<span style="color: #000000; font-weight: bold;">/</span>ruby-1.9.2-p180<span style="color: #000000; font-weight: bold;">/</span>include<span style="color: #000000; font-weight: bold;">/</span>ruby-1.9.1<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>ruby.h:<span style="color: #000000;">1327</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;from <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>peter<span style="color: #000000; font-weight: bold;">/</span>.rvm<span style="color: #000000; font-weight: bold;">/</span>rubies<span style="color: #000000; font-weight: bold;">/</span>ruby-1.9.2-p180<span style="color: #000000; font-weight: bold;">/</span>include<span style="color: #000000; font-weight: bold;">/</span>ruby-1.9.1<span style="color: #000000; font-weight: bold;">/</span>ruby.h:<span style="color: #000000;">32</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;from .<span style="color: #000000; font-weight: bold;">/</span>mysql2_ext.h:<span style="color: #000000;">4</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;from client.c:<span style="color: #000000;">1</span>:<br />
<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>peter<span style="color: #000000; font-weight: bold;">/</span>.rvm<span style="color: #000000; font-weight: bold;">/</span>rubies<span style="color: #000000; font-weight: bold;">/</span>ruby-1.9.2-p180<span style="color: #000000; font-weight: bold;">/</span>include<span style="color: #000000; font-weight: bold;">/</span>ruby-1.9.1<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>st.h:<span style="color: #000000;">69</span>: error: <span style="color: #c20cb9; font-weight: bold;">size</span> of array ‘st_check_for_sizeof_st_index_t’ is negative</div></div>
<h2>The Solution</h2>
<p>Uninstall your MySQL using the commands below</h2>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <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>mysql<br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <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>mysql<span style="color: #000000; font-weight: bold;">*</span><br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</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>MySQLCOM<br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>PreferencePanes<span style="color: #000000; font-weight: bold;">/</span>My<span style="color: #000000; font-weight: bold;">*</span><br />
edit <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>hostconfig and remove the line <span style="color: #007800;">MYSQLCOM</span>=-YES-<br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Receipts<span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">*</span><br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Receipts<span style="color: #000000; font-weight: bold;">/</span>MySQL<span style="color: #000000; font-weight: bold;">*</span></div></div>
<p>Now go and download the 64 bit version of the MySQL package &#8211; get the dmg rather than the gzip file.</p>
<p>The rationale behind this is that your new beaut 10.6 is actually referencing 64 bit modules by default. How to prove this I do not know &#8211; I&#8217;m confused and still searching for the answer. If I do a uname &#8211; a I get&#8230;</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Darwin MacBook-Air.local 10.6.0 Darwin Kernel Version 10.6.0: Wed Nov <span style="color: #000000;">10</span> <span style="color: #000000;">18</span>:<span style="color: #000000;">13</span>:<span style="color: #000000;">17</span> PST <span style="color: #000000;">2010</span>; root:xnu-1504.9.26~<span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span>RELEASE_I386 i386</div></div>
<p>Now, if I&#8217;m not mistaken that&#8217;s an i386 at the end &#8211; go figure. If anyone has any further insights please let me know.</p>
<p>The next step is to download the gem for your ruby/rails use</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">env</span> <span style="color: #007800;">ARCHFLAGS</span>=<span style="color: #ff0000;">&quot;-arch x86_64&quot;</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> mysql <span style="color: #660033;">--</span> \<br />
&nbsp; <span style="color: #660033;">--with-mysql-dir</span>=<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>mysql <span style="color: #660033;">--with-mysql-lib</span>=<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>mysql<span style="color: #000000; font-weight: bold;">/</span>lib \<br />
&nbsp; <span style="color: #660033;">--with-mysql-include</span>=<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>mysql<span style="color: #000000; font-weight: bold;">/</span>include</div></div>
<p>The next error encountered is when I try to start the rails server using &#8216;rails s&#8217;</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>peter<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>gems<span style="color: #000000; font-weight: bold;">/</span>mysql2-0.2.6<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>mysql2.rb:<span style="color: #000000;">7</span>:<span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span>require<span style="color: #ff0000;">': dlopen(/Users/peter/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.16.dylib (LoadError)</span></div></div>
<p>The answer to this problem is to run the following command&#8230;</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">sudo</span> install_name_tool <span style="color: #660033;">-change</span> libmysqlclient.16.dylib <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>mysql<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>libmysqlclient.16.dylib ~<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>gems<span style="color: #000000; font-weight: bold;">/</span>mysql2-0.2.6<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>mysql2<span style="color: #000000; font-weight: bold;">/</span>mysql2.bundle<span style="color: #000000; font-weight: bold;">/</span></div></div>
<p>Bear in mind, I&#8217;m running version 1.9.2-p180 fo ruby &#8211; you will need to change the command for whatever version you&#8217;re running.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.petermac.com%2Finstalling-mysql-gem-on-osx-10-6%2F&amp;title=Installing%20MySQL%20gem%20on%20OSX%2010.6" id="wpa2a_2"><img src="http://www.petermac.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.petermac.com/installing-mysql-gem-on-osx-10-6/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Rails 3, jQuery and multi-select dependencies</title>
		<link>http://www.petermac.com/rails-3-jquery-and-multi-select-dependencies/</link>
		<comments>http://www.petermac.com/rails-3-jquery-and-multi-select-dependencies/#comments</comments>
		<pubDate>Fri, 13 Aug 2010 05:41:14 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.petermac.com/?p=431</guid>
		<description><![CDATA[I&#8217;ve just upgraded to Rails 3 and hit a real blocker that&#8217;s taken me two days to work out. I hope this post can save someone else even a few hours of stuffing around with Rails 3, jQuery, unobtrusive javascript and other assorted gems. The problem I have a user profile form with dropdown selects [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just upgraded to Rails 3 and hit a real blocker that&#8217;s taken me two days to work out. I hope this post can save someone else even a few hours of stuffing around with Rails 3, jQuery, unobtrusive javascript and other assorted gems.</p>
<h2>The problem</h2>
<p>I have a user profile form with dropdown selects for country, region and city. To start out, only the country select is populated. When the user selects a country, the region select populates with regions from that country, when a region (aka state/territory) is selected, the city list is populated. I know there are countries that don&#8217;t have regions, but that&#8217;s another day&#8217;s thinking.</p>
<p>My setup is fairly simple. I&#8217;m using jQuery, NOT prototype, so there&#8217;s no observe_field. Try to use such will result in an error &#8216;observer_field undefined method&#8217;. I&#8217;m using formtastic as a UI helper because I&#8217;ve been impressed by it&#8217;s DRYness and I&#8217;m tired of coding html forms. This solution shows the formtastic layouts, but can be applied to standard rails forms very easilyy.</p>
<h2>jQuery setup</h2>
<p>I&#8217;m using the jQuery 1.4.2 minimized version of the file from Google and a jquery/ujs wrapper/helper file I downloaded from github at <a href="http://github.com/rails/jquery-ujs/blob/master/src/rails.js" target="blank">http://github.com/rails/jquery-ujs/blob/master/src/rails.js</a>.<br />
I renamed this file as rails.jquery.js and copied it to the folder public/javascripts/ under the root of my application folder.</p>
<p>Next step is to update the javascript files that are included in the header of your application. So, open up app/views/layouts/application.html.erb</p>
<div class="codecolorer-container ruby blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;<span style="color:#006600; font-weight:bold;">&lt;%</span>= javascript_include_tag <span style="color:#996600;">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js&quot;</span>, <span style="color:#996600;">&quot;rails.jquery.js&quot;</span>, <span style="color:#996600;">&quot;application.js&quot;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&nbsp; <span style="color:#006600; font-weight:bold;">&lt;%</span>= csrf_meta_tag <span style="color:#006600; font-weight:bold;">%&gt;</span></div></div>
<p>The javascript_include tag lists specifically those files I need. If you use the &#8220;defaults&#8221; option you&#8217;ll end up with the prototype.js included in the mix. This is something I&#8217;m trying to avoid given it&#8217;s not UJS.</p>
<p>The csrf_meta_tag reference is a Rails 3 enhancement. It seeks to avoid cross site scripting issues by ensuring the token created by the authenticated visitor is maintained throughout the site, thereby ensuring that a button click or post back has actually come from a genuine session.</p>
<h2>Update routes.rb</h2>
<p>When a change of a select list is triggerd, an Ajax post will be made to my profiles controller (remember we&#8217;re dealing with the &#8216;profile&#8217; model here). I&#8217;m using two actions, update_state_select and update_city_select.<br />
To add these calls into the routes.rb file, update it with the following:</p>
<div class="codecolorer-container ruby blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">resources <span style="color:#ff3333; font-weight:bold;">:profiles</span><br />
<br />
&nbsp; match <span style="color:#996600;">'profiles/update_state_select/:id'</span>, <span style="color:#ff3333; font-weight:bold;">:controller</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#996600;">'profiles'</span>, <span style="color:#ff3333; font-weight:bold;">:action</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'update_state_select'</span><br />
<br />
&nbsp; match <span style="color:#996600;">'profiles/update_city_select/:id'</span>, <span style="color:#ff3333; font-weight:bold;">:controller</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#996600;">'profiles'</span>, <span style="color:#ff3333; font-weight:bold;">:action</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'update_city_select'</span></div></div>
<h2>The main form</h2>
<p>The form where users can enter their new profile details is called new.html.erb and resides under the app/views/profiles folder. It&#8217;s a formtastic form, but once you&#8217;ve seen the code, you can do the mental shift to whatever other UI component you fancy.</p>
<div class="codecolorer-container ruby blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#006600; font-weight:bold;">&lt;%</span> semantic_form_for <span style="color:#0066ff; font-weight:bold;">@profile</span>, <span style="color:#ff3333; font-weight:bold;">:remote</span><span style="color:#006600; font-weight:bold;">=&gt;</span>true, <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>form<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&lt;%</span> form.<span style="color:#9900CC;">inputs</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&lt;%</span>= form.<span style="color:#9900CC;">input</span> <span style="color:#ff3333; font-weight:bold;">:firstname</span> <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&lt;%</span>= form.<span style="color:#9900CC;">input</span> <span style="color:#ff3333; font-weight:bold;">:middlename</span> <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&lt;%</span>= form.<span style="color:#9900CC;">input</span> <span style="color:#ff3333; font-weight:bold;">:lastname</span> <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&lt;%</span>= form.<span style="color:#9900CC;">input</span> <span style="color:#ff3333; font-weight:bold;">:image</span>, <span style="color:#ff3333; font-weight:bold;">:as</span><span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:file</span> <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&lt;%</span>= form.<span style="color:#9900CC;">input</span> <span style="color:#ff3333; font-weight:bold;">:timezone_adjustment</span>, <span style="color:#ff3333; font-weight:bold;">:as</span><span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:time_zone</span> <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&lt;%</span>= form.<span style="color:#9900CC;">input</span> <span style="color:#ff3333; font-weight:bold;">:gender</span>, <span style="color:#ff3333; font-weight:bold;">:as</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:radio</span>, <span style="color:#ff3333; font-weight:bold;">:label</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;Gender&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:collection</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;Male&quot;</span>, <span style="color:#996600;">&quot;M&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;Female&quot;</span>, <span style="color:#996600;">&quot;F&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&lt;%</span>= form.<span style="color:#9900CC;">input</span> <span style="color:#ff3333; font-weight:bold;">:birthday</span>, <span style="color:#ff3333; font-weight:bold;">:as</span><span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:date</span>, <span style="color:#ff3333; font-weight:bold;">:start_year</span> <span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#006666;">1930</span> <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&lt;%</span>= form.<span style="color:#9900CC;">input</span> <span style="color:#ff3333; font-weight:bold;">:facebook_profile_url</span> <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&lt;%</span>= form.<span style="color:#9900CC;">input</span> <span style="color:#ff3333; font-weight:bold;">:linkedin_profile_url</span> <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&lt;%</span>= form.<span style="color:#9900CC;">input</span> <span style="color:#ff3333; font-weight:bold;">:country_id</span>, <span style="color:#ff3333; font-weight:bold;">:collection</span><span style="color:#006600; font-weight:bold;">=&gt;</span>Country.<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;">:order</span><span style="color:#006600; font-weight:bold;">=&gt;</span>:name<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">collect</span><span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>c<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">&#91;</span>c.<span style="color:#9900CC;">name</span>,c.<span style="color:#9900CC;">id</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#ff3333; font-weight:bold;">:required</span><span style="color:#006600; font-weight:bold;">=&gt;</span>true <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;div id=&quot;addressStates&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <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;">'states'</span> &nbsp;<span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;div id=&quot;addressCities&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; <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;">'cities'</span> &nbsp;<span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&nbsp; &nbsp; &lt;/div&gt;<br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&lt;%</span>= form.<span style="color:#9900CC;">buttons</span> <span style="color:#ff3333; font-weight:bold;">:commit</span> <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&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><br />
<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></div></div>
<h2>Handle the change events</h2>
<p>We have to add in the javascript now that will get fired when the first select (the country list) is changed. This is a piece of javascript code I&#8217;ve decided to put into the application.js file under the public/javascripts file.<br />
The code looks like this:</p>
<div class="codecolorer-container javascript blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">jQuery<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><br />
&nbsp; <span style="color: #006600; font-style: italic;">// when the #country field changes</span><br />
&nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#profile_country_id&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">change</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><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// make a POST call and replace the content</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> country <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'select#profile_country_id :selected'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>country <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> country<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;0&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; jQuery.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'/profiles/update_state_select/'</span> <span style="color: #339933;">+</span> country<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#addressStates&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span></div></div>
<p>What&#8217;s happening here is the jQuery code is waiting for a change to be triggered by a control called &#8216;profile_country_id&#8217;. When a change is detected, it&#8217;s taking the value of the selected value and passing it as a parameter to the get call on profiles/update_state_select. The results of the call will end up being rendered as html in the addressStates div.</p>
<p>If you have firebug installed (and you should!!) you can see the javascript get being triggered in the console window. If you haven&#8217;t implemented the update_state_select method in your controller, you&#8217;ll probably get a 404 error.</p>
<h2>The controller</h2>
<p>This is the simple bit apart from a few minor tweaks to accommodate Rails 3 ActiveRecord queries</p>
<div class="codecolorer-container ruby blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">def</span> update_state_select<br />
&nbsp; &nbsp; states = Region.<span style="color:#9900CC;">where</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:country_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;">:id</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">order</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:name</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">unless</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:#9900CC;">blank</span>?<br />
&nbsp; &nbsp; render <span style="color:#ff3333; font-weight:bold;">:partial</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;states&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:locals</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;">:states</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> states <span style="color:#006600; font-weight:bold;">&#125;</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></div>
<p>Note the use of the &#8216;where&#8217; and the &#8216;order&#8217; methods applied directly to the entity name. I think this is one of the neatest changes in the Rails 3 ActiveRecord domain. I&#8217;m going to have to build an automation utility to update all my old code.</p>
<h2>Rendering the partial</h2>
<p>In the simplest case, the partial that displays the states should just be a select populated with the results of the update_state_select method call. There&#8217;s a &#8216;but&#8230;&#8217; coming up so pay attention.</p>
<div class="codecolorer-container ruby blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">#This is _states.html.erb stage 1 - without the jQuery code<br />
<span style="color:#006600; font-weight:bold;">&lt;%</span>= semantic_form_for <span style="color:#996600;">&quot;profile&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:remote</span><span style="color:#006600; font-weight:bold;">=&gt;</span>true, <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>form<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&nbsp; <span style="color:#006600; font-weight:bold;">&lt;%</span>= form.<span style="color:#9900CC;">inputs</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">if</span> !states.<span style="color:#9900CC;">blank</span>? <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&lt;%</span>= form.<span style="color:#9900CC;">input</span> <span style="color:#ff3333; font-weight:bold;">:region_id</span>, <span style="color:#ff3333; font-weight:bold;">:collection</span><span style="color:#006600; font-weight:bold;">=&gt;</span>states.<span style="color:#9900CC;">collect</span><span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>s<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">&#91;</span>s.<span style="color:#9900CC;">name</span>,s.<span style="color:#9900CC;">id</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;">%&gt;</span><br />
&nbsp; &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><br />
&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&lt;%</span>= form.<span style="color:#9900CC;">input</span> <span style="color:#ff3333; font-weight:bold;">:region_id</span>, <span style="color:#ff3333; font-weight:bold;">:collection</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&nbsp; &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><br />
&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><br />
<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></div></div>
<p>So far it&#8217;s looking good, when a user selects the country drop-down the jQuery event is triggered, that does a Get to the controller. The controller builds a collection and passes it to the _states partial. However, (this is the &#8216;but&#8217; I mentioned) I couldn&#8217;t get the change event of the state drop-down unless I put the jQuery code in as part of the partial. If anyone knows what/how to add this code to the application.js and still get it to fire, please let me know.</p>
<p>To get the change event of the state_id select to trigger, add the following code to the top of the _state.html.erb file. Note how similar it is to the code in the application.js file</p>
<div class="codecolorer-container ruby blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#006600; font-weight:bold;">&lt;</span>script type=<span style="color:#996600;">&quot;text/javascript&quot;</span><span style="color:#006600; font-weight:bold;">&gt;</span><br />
jQuery<span style="color:#006600; font-weight:bold;">&#40;</span>function<span style="color:#006600; font-weight:bold;">&#40;</span>$<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
<span style="color:#006600; font-weight:bold;">//</span> <span style="color:#9966CC; font-weight:bold;">when</span> the <span style="color:#008000; font-style:italic;">#region_id field changes</span><br />
&nbsp; $<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;#profile_region_id&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">change</span><span style="color:#006600; font-weight:bold;">&#40;</span>function<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">//</span> make a POST call <span style="color:#9966CC; font-weight:bold;">and</span> replace the content<br />
&nbsp; &nbsp; var state = $<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'select#profile_region_id :selected'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">val</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span>state == <span style="color:#996600;">&quot;&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> state=<span style="color:#996600;">&quot;0&quot;</span>;<br />
&nbsp; &nbsp; jQuery.<span style="color:#9900CC;">get</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'/profiles/update_city_select/'</span> <span style="color:#006600; font-weight:bold;">+</span> state, function<span style="color:#006600; font-weight:bold;">&#40;</span>data<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; $<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;#addressCities&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">html</span><span style="color:#006600; font-weight:bold;">&#40;</span>data<span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0000FF; font-weight:bold;">false</span>;<br />
&nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<span style="color:#006600; font-weight:bold;">&lt;/</span>script<span style="color:#006600; font-weight:bold;">&gt;</span></div></div>
<p>Now we have a functioning form with an Ajax enabled country and state select lists. All that&#8217;s left to do is to do a copy and paste of code in the profiles controller to get the update_city_select method working and add a new _cities.html.erb partial to display the results of the controller method call.</p>
<p>Here&#8217;s all the relevant code for the controllers/profiles_controller.rb file:</p>
<div class="codecolorer-container ruby blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">def</span> update_city_select<br />
&nbsp; &nbsp; cities = City.<span style="color:#9900CC;">where</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:region_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;">:id</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">order</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:name</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">unless</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:#9900CC;">blank</span>?<br />
&nbsp; &nbsp; render <span style="color:#ff3333; font-weight:bold;">:partial</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;cities&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:locals</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;">:cities</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> cities <span style="color:#006600; font-weight:bold;">&#125;</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></div>
<p>And the code for the app/views/profiles/_cities.html.erb partial:</p>
<div class="codecolorer-container ruby blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#006600; font-weight:bold;">&lt;%</span>= semantic_form_for <span style="color:#996600;">&quot;profile&quot;</span>, <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>form<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&nbsp; <span style="color:#006600; font-weight:bold;">&lt;%</span>= form.<span style="color:#9900CC;">inputs</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">if</span> !cities.<span style="color:#9900CC;">blank</span>? <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&lt;%</span>= form.<span style="color:#9900CC;">input</span> <span style="color:#ff3333; font-weight:bold;">:city_id</span>, <span style="color:#ff3333; font-weight:bold;">:collection</span><span style="color:#006600; font-weight:bold;">=&gt;</span>cities.<span style="color:#9900CC;">collect</span><span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>c<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">&#91;</span>c.<span style="color:#9900CC;">name</span>,c.<span style="color:#9900CC;">id</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;">%&gt;</span><br />
&nbsp; &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><br />
&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&lt;%</span>= form.<span style="color:#9900CC;">input</span> <span style="color:#ff3333; font-weight:bold;">:city_id</span>, <span style="color:#ff3333; font-weight:bold;">:collection</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&nbsp; &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><br />
&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><br />
<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></div></div>
<h2>Summary</h2>
<p>I hit the first wall when I added an observe_field and couldn&#8217;t explain why I was getting method undefined errors. That started me down a long and winding road of frustration. I think I&#8217;ve overcome most of the frustrations and I&#8217;m starting to get the hang of the Rails 3 changes.</p>
<p>There is a plugin that will allow you to keep your old Rails 2 ways alive but every time I saw mention of it, I also saw comments about how bad an idea it is. I mean, you could probably also run some COBOL code as a plugin, but why live in the past?</p>
<h2>References</h2>
<p>
<a href="http://github.com/rails/jquery-ujs/" target="blank">jQuery files from Github</a></p>
<p><a href="http://github.com/justinfrench/formtastic" target="blank">Formtastic plugin</a></p>
<p>Beware: Use the proper branch for Rails 3 gem &#8216;formtastic&#8217;, :git => &#8220;http://github.com/justinfrench/formtastic.git&#8221;, :branch => &#8220;rails3&#8243;</p>
<p><a href="http://www.simonecarletti.com/blog/2010/06/unobtrusive-javascript-in-rails-3/" target="blank">Simone Carletti&#8217;s Blog</a></p>
<p><a href="http://railscasts.com/" target="blank">Ryan Bates&#8217; excellent video cast series</a></p>
<p>A couple of people asked me to show more info on the actual table design and models used in this example. You can read more on this site by following this link <a href="http://www.petermac.com/rails-3-jquery-and-multiselect-dependencies-part-2">Rails 3, jQuery and multiselect dependencies part 2.</a></p>
<p>Comments, questions and suggestions welcome</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.petermac.com%2Frails-3-jquery-and-multi-select-dependencies%2F&amp;title=Rails%203%2C%20jQuery%20and%20multi-select%20dependencies" id="wpa2a_4"><img src="http://www.petermac.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.petermac.com/rails-3-jquery-and-multi-select-dependencies/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Ruby/Rails 3 and PostgreSQL</title>
		<link>http://www.petermac.com/rubyrails-3-and-postgresql/</link>
		<comments>http://www.petermac.com/rubyrails-3-and-postgresql/#comments</comments>
		<pubDate>Mon, 02 Aug 2010 04:48:26 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.petermac.com/?p=345</guid>
		<description><![CDATA[I&#8217;ve just spent an hour arguing with a new install of ruby 1.92, rails 3.0.2rc and PostgreSQL. Every time i tried to do a db:migrate I got a strange error. rake db:migrate (in /home/peter/projects/workspace/testapp) rake aborted! no such file to load -- pg I did the usual trawling around helpful websites, each suggesting I hadn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just spent an hour arguing with a new install of ruby 1.92, rails 3.0.2rc and PostgreSQL.</p>
<p>Every time i tried to do a db:migrate I got a strange error.</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">rake db:migrate<br />
(in /home/peter/projects/workspace/testapp)<br />
rake aborted!<br />
no such file to load -- pg</div></div>
<p>
I did the usual trawling around helpful websites, each suggesting I hadn&#8217;t the correct database gem installed. some referred to pg, some to postgresql, other to ruby-postgres.</p>
<p>What I have installed is listed below</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">abstract (1.0.0)<br />
actionmailer (3.0.0.rc)<br />
actionpack (3.0.0.rc)<br />
activemodel (3.0.0.rc)<br />
activerecord (3.0.0.rc)<br />
activeresource (3.0.0.rc)<br />
activesupport (3.0.0.rc)<br />
arel (0.4.0)<br />
builder (2.1.2)<br />
bundler (1.0.0.rc.2)<br />
capistrano (2.5.19)<br />
erubis (2.6.6)<br />
highline (1.6.1)<br />
i18n (0.4.1)<br />
mail (2.2.5)<br />
mime-types (1.16)<br />
minitest (1.6.0)<br />
net-scp (1.0.2)<br />
net-sftp (2.0.4)<br />
net-ssh (2.0.23)<br />
net-ssh-gateway (1.0.1)<br />
pg (0.9.0)<br />
polyglot (0.3.1)<br />
rack (1.2.1)<br />
rack-mount (0.6.9)<br />
rack-test (0.5.4)<br />
rails (3.0.0.rc)<br />
railties (3.0.0.rc)<br />
rake (0.8.7)<br />
rdoc (2.5.8)<br />
sqlite3-ruby (1.3.1)<br />
thor (0.14.0)<br />
treetop (1.4.8)<br />
tzinfo (0.3.22)</div></div>
<p>The fix for the &apos;no such file to load &#8212; pg&apos; error is to update the new Gemfile file in your application&#8217;s root folder.</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">#Comment out the sqlite3 requirement<br />
#gem 'sqlite3-ruby', :require =&gt; 'sqlite3'<br />
#Add a pg requirement<br />
gem 'pg', :require =&gt; 'pg'</div></div>
<p>Once you&#8217;ve done this do a bundle install from your application root folder. This ensures you have all required gems installed. Another hour wasted fighting against the machine.</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ sudo bundle install</div></div>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.petermac.com%2Frubyrails-3-and-postgresql%2F&amp;title=Ruby%2FRails%203%20and%20PostgreSQL" id="wpa2a_6"><img src="http://www.petermac.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.petermac.com/rubyrails-3-and-postgresql/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Internationalized country/state/city database</title>
		<link>http://www.petermac.com/internationalized-countrystatecity-database/</link>
		<comments>http://www.petermac.com/internationalized-countrystatecity-database/#comments</comments>
		<pubDate>Wed, 28 Jul 2010 10:37:11 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.petermac.com/?p=292</guid>
		<description><![CDATA[I&#8217;ve just posted a little project up to the gitorious website for my and other&#8217;s pleasure. The last few freelance projects I&#8217;ve worked on have required the functionality to provide users with a way to enter their location using a prompt system by selecting country first, then entering their region/state and finally their town and [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just posted a little project up to the gitorious website for my and other&#8217;s pleasure. The last few freelance projects I&#8217;ve worked on have required the functionality to provide users with a way to enter their location using a prompt system by selecting country first, then entering their region/state and finally their town and city. The database structure uses a standard Rails convention and is MySQL based. It can be very easily converted to any other SQL supported format.</p>
<p>
<a href="http://gitorious.org/internationalised-country-city-region-database" target="blank">Click here to browse to the project.</a></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.petermac.com%2Finternationalized-countrystatecity-database%2F&amp;title=Internationalized%20country%2Fstate%2Fcity%20database" id="wpa2a_8"><img src="http://www.petermac.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.petermac.com/internationalized-countrystatecity-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ubuntu 10.04 setup for Ruby on Rails and general use</title>
		<link>http://www.petermac.com/ubuntu-1004-setup-for-ruby-on-rails-and-general-use/</link>
		<comments>http://www.petermac.com/ubuntu-1004-setup-for-ruby-on-rails-and-general-use/#comments</comments>
		<pubDate>Sat, 03 Jul 2010 09:13:55 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[GNU/Linux]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.petermac.com/?p=107</guid>
		<description><![CDATA[This extract is from notes I took during the process of setting up both a desktop and laptop for general use as a development environment for Ruby on Rails (RoR) and PHP development. There were lots of other steps (custom gems and environment stuff I like), but most of what follows is generic enough to [...]]]></description>
			<content:encoded><![CDATA[<p>This extract is from notes I took during the process of setting up both a desktop and laptop for general use as a development environment for Ruby on Rails (RoR) and PHP development.</p>
<p>There were lots of other steps (custom gems and environment stuff I like), but most of what follows is generic enough to get the basics in place.  Happy Hacking!!</p>
<p>Installing Skype</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><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> libqt4-dbus libqt4-network libqt4-xml libasound2<br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">dpkg</span> <span style="color: #660033;">-i</span> skype-ubuntu-intrepid_2.1.0.81-<span style="color: #000000;">1</span>_amd64.deb</div></div>
<p>Installing Amarok</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><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> xine-ui libxine1-ffmpeg</div></div>
<p>To get remote shares mapping in fstab.</p>
<p>Firstly, install the smb client package</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> smbfs<br />
<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> portmap nfs-common</div></div>
<p>Then add the following line to /etc/hosts.deny:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">echo</span> portmap : ALL<span style="color: #000000; font-weight: bold;">&gt;&gt;/</span>etc<span style="color: #000000; font-weight: bold;">/</span>hosts.deny</div></div>
<p>By blocking all clients first, only clients in /etc/hosts.allow below will be allowed to access the server.</p>
<p>Now add the following line to /etc/hosts.allow. User your own IP address.</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">echo</span> portmap : 192.168.0.20<span style="color: #000000; font-weight: bold;">&gt;&gt;</span>hosts.allow</div></div>
<p>Next create the mounting points on your system</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/&lt;</span>name of mounting point<span style="color: #000000; font-weight: bold;">&gt;</span><br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>music<br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>backups</div></div>
<p>Create a file in home folder called .smbcredentials (note the leading dot)</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">touch</span> ~<span style="color: #000000; font-weight: bold;">/</span>.smbcredentials<br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">username</span>=<span style="color: #7a0874; font-weight: bold;">&#91;</span>your network username<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> ~<span style="color: #000000; font-weight: bold;">/</span>.smbcredentials<br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">password</span>=<span style="color: #7a0874; font-weight: bold;">&#91;</span>your network password<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> ~<span style="color: #000000; font-weight: bold;">/</span>.smbcredentials<br />
<span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">600</span> ~<span style="color: #000000; font-weight: bold;">/</span>.smbcredentials</div></div>
<p>Now an entry in /etc/fstab using the ip address of your NAS</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#Added a permanent share to shares on NAS box</span><br />
<span style="color: #666666; font-style: italic;">#Note: everything that follows (up to the 0 &nbsp;0 should appear on the one line)</span><br />
<span style="color: #666666; font-style: italic;">#and one line is required for each share you want to map</span><br />
<br />
<span style="color: #000000; font-weight: bold;">//</span>192.168.0.20<span style="color: #000000; font-weight: bold;">/&lt;</span>foldername on NAS<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/&lt;</span><span style="color: #7a0874; font-weight: bold;">local</span> foldername<span style="color: #000000; font-weight: bold;">&gt;</span> cifs<br />
<span style="color: #007800;">uid</span>=peter,<span style="color: #007800;">credentials</span>=<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>peter<span style="color: #000000; font-weight: bold;">/</span>.smbcredentials,<span style="color: #007800;">domain</span>=office,<span style="color: #007800;">dir_mode</span>=0777,<span style="color: #007800;">file_mode</span>=0777 <span style="color: #000000;">0</span> &nbsp; &nbsp; &nbsp; <span style="color: #000000;">0</span></div></div>
<p>Now, for a few of the other standard tools<br />
Setup filezilla and limewire</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> filezilla<br />
<br />
<span style="color: #666666; font-style: italic;">#Limewire - download LimeWireLinux.deb from limewire site</span><br />
<span style="color: #666666; font-style: italic;"># reports missing dependencies</span><br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">dpkg</span> <span style="color: #660033;">-i</span> LimeWireLinux.deb<br />
limewire-basic depends on sun-java6-jre <span style="color: #000000; font-weight: bold;">|</span> icedtea-java7-jre <span style="color: #000000; font-weight: bold;">|</span><br />
sun-java6-jdk <span style="color: #000000; font-weight: bold;">|</span> icedtea-java7-jdk; however:<br />
Package sun-java6-jre is not installed.<br />
Package icedtea-java7-jre is not installed.<br />
Package sun-java6-jdk is not installed.<br />
Package icedtea-java7-jdk is not installed.<br />
<span style="color: #c20cb9; font-weight: bold;">dpkg</span>: error processing limewire-basic <span style="color: #7a0874; font-weight: bold;">&#40;</span>--install<span style="color: #7a0874; font-weight: bold;">&#41;</span>:<br />
dependency problems - leaving unconfigured</div></div>
<p>Open synaptic package manager. Go to the Settings/Repositories/Other sources tab.<br />
Check the two default partner sites. Reload the package list and select the following</p>
<p>sun-java6-jre<br />
sun-java6-plugin<br />
sun-java6-fonts packages</p>
<p>Now retry limewire and you&#8217;re smoking.</p>
<p>Installing ruby and associated gems</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><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> ruby<br />
<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> rubygems<br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> rake<br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> rails</div></div>
<p>I tried to install capistrano using sudo but it wasn&#8217;t working on laptop however it did work on desktop</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">gem <span style="color: #c20cb9; font-weight: bold;">install</span> capistrano</div></div>
<p>Then change ~/.bashrc to include path to new gems</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">emacs ~<span style="color: #000000; font-weight: bold;">/</span>.bashrc <span style="color: #000000; font-weight: bold;">&amp;</span><br />
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PATH</span>=<span style="color: #007800;">$PATH</span>:~<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>bin:<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<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>bin</div></div>
<p>Now install and configure mysql before trying to install any of the ruby mysql gems</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">install</span> mysql server<br />
<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> mysql-server</div></div>
<p>Setup prompts you for a password &#8211; enter it, remember it and enter it again.</p>
<p>Install the mysql admin tools</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><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> mysql-admin</div></div>
<p><b>NB &#8211; must install the libmysqlclient[nn]-dev package</b><br />
This has mysql_config bundled with it which is needed by the ruby gems</p>
<p>Execute the following to find out what version of libmysqlclient you&#8217;re running</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">dpkg</span> <span style="color: #660033;">--get-selections</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> mysqlclient</div></div>
<p>In my case it&#8217;s version 16, so execute the following</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><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> libmysqlclient16-dev</div></div>
<p><b>Next, you NEED TO INSTALL the ruby1.8 dev package</b><br />
If you don&#8217;t you&#8217;ll get all sorts of mysql gem errors &#8212; frustrating!!!</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><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> ruby1.8-dev<br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> mysql</div></div>
<p>Installing and configuring git</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><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> git-core<br />
<span style="color: #c20cb9; font-weight: bold;">git</span> config <span style="color: #660033;">--global</span> user.email</div></div>
<p>Installing apache</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><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> apache2</div></div>
<p>The line above should do it, if you get any glitches, try the following</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><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> apache2.2-bin<br />
<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> apache2.2-common<br />
<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> apache2-threaded-dev</div></div>
<p>Installing php</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><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> php5<br />
<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> php5-mysql</div></div>
<p>Anything else is stuffing around with particular ruby gems and dev tools so probably too specific for this note.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.petermac.com%2Fubuntu-1004-setup-for-ruby-on-rails-and-general-use%2F&amp;title=Ubuntu%2010.04%20setup%20for%20Ruby%20on%20Rails%20and%20general%20use" id="wpa2a_10"><img src="http://www.petermac.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.petermac.com/ubuntu-1004-setup-for-ruby-on-rails-and-general-use/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

