<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">
  	<title>syedaslam.com</title>
  	
  	<link rel="alternate" type="text/html" href="http://syedaslam.com/" />
  	
  	
  	<id>http://syedaslam.com/</id>
  	<updated>2011-04-05T17:23:59+05:30</updated>
  	<subtitle>a blog about programming</subtitle>
  
  	<author>
   		<name>Syed Aslam</name>
   		<email>aslam.maqsood@gmail.com</email>
	</author>
  
  	
 		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/syedaslam" /><feedburner:info uri="syedaslam" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>syedaslam</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><entry>
   			<title>Retrieving random row from a table</title>
   			<link href="http://feedproxy.google.com/~r/syedaslam/~3/C4_HcVAbPtQ/retrieving-random-row-table" />
   			<updated>2011-04-05T00:00:00+05:30</updated>
   			<id>http://syedaslam.com/2011/04/05/retrieving-random-row-table</id>
   			<content type="html">&lt;p&gt; To retrive a random row from a table you have do just this: &lt;/p&gt;




&lt;div class="code"&gt;
&lt;pre&gt; Model.find :first, :offset =&gt; ( Model.count * rand ).to_i &lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;
This is fast and requires no custom SQL queries! All this does is count number of rows in a table and select one row at some offset while still having the table ordered by primary key. 
&lt;/p&gt;




&lt;p&gt;
It uses offset (limit), not ID number, so it chooses n-th found row, not a row with ID equal to n. So if you have IDs like &lt;span class="highlight"&gt;1, 2, 4, 8&lt;/span&gt;and get 3 at random, this method will take &lt;span class="highlight"&gt;3rd row&lt;/span&gt;, which has &lt;span class="highlight"&gt;ID = 4&lt;/span&gt;. 
&lt;/p&gt;

&lt;img src="http://feeds.feedburner.com/~r/syedaslam/~4/C4_HcVAbPtQ" height="1" width="1"/&gt;</content>
 		<feedburner:origLink>http://syedaslam.com/2011/04/05/retrieving-random-row-table</feedburner:origLink></entry>
 	
 		<entry>
   			<title>Recover MySQL root Password</title>
   			<link href="http://feedproxy.google.com/~r/syedaslam/~3/i8V-JLKnRsk/recover-root-password-mysql" />
   			<updated>2011-03-31T00:00:00+05:30</updated>
   			<id>http://syedaslam.com/2011/03/31/recover-root-password-mysql</id>
   			<content type="html">&lt;p&gt;
You can recover MySQL database server password with following five easy steps.
&lt;/p&gt;




&lt;p&gt; Step # 1: Stop the MySQL server process. &lt;/p&gt;




&lt;div class="code"&gt;
&lt;pre&gt; # sudo /etc/init.d/mysql stop &lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;
Step # 2: Start the MySQL (mysqld) server/daemon process with the 
&lt;span class="highlight"&gt;--skip-grant-tables &lt;/span&gt;option so that it will not
prompt for password.
&lt;/p&gt;




&lt;div class="code"&gt;
&lt;pre&gt; # sudo mysqld_safe --skip-grant-tables &amp; &lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt; Step # 3: Connect to mysql server as the root user. &lt;/p&gt;




&lt;div class="code"&gt; &lt;pre&gt; # mysql -u root &lt;/pre&gt; &lt;/div&gt;




&lt;p&gt; 
Step # 4: Setup new mysql root account password i.e. reset mysql password. 
&lt;/p&gt;




&lt;div class="code"&gt;
&lt;pre&gt;
mysql&gt; use mysql;
mysql&gt; update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
mysql&gt; flush privileges;
mysql&gt; quit
&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt; Step # 5: Exit and restart the MySQL server. &lt;/p&gt;




&lt;div class="code"&gt;
&lt;pre&gt;
# sudo /etc/init.d/mysql stop

# sudo /etc/init.d/mysql start

# mysql -u root -p
&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt; You have just changed the password for the root user of mysql database. &lt;/p&gt;

&lt;img src="http://feeds.feedburner.com/~r/syedaslam/~4/i8V-JLKnRsk" height="1" width="1"/&gt;</content>
 		<feedburner:origLink>http://syedaslam.com/2011/03/31/recover-root-password-mysql</feedburner:origLink></entry>
 	
 		<entry>
   			<title>Highlighting current link within a navigation list in rails</title>
   			<link href="http://feedproxy.google.com/~r/syedaslam/~3/_LEjgOPKNl0/highlight-current-link" />
   			<updated>2011-03-28T00:00:00+05:30</updated>
   			<id>http://syedaslam.com/2011/03/28/highlight-current-link</id>
   			<content type="html">&lt;p&gt;
It's very common to want to highlight the current link within a navigation list for the current action being performed. If you are using Ajax, then this is easy, handle the &lt;span class="highlight"&gt;onclick&lt;/span&gt; event to highlight the current link. 
&lt;/p&gt;




&lt;div class="code"&gt;
&lt;pre&gt;
&lt;%= link_to 'Home', 'javascript:void(0);', 
  :onclick =&gt; "this.addClassName('youarehere');this.siblings().each(function(s){
  s.removeClassName('youarehere');});", :class =&gt; '', :id =&gt; 'home' %&gt; 

&lt;%= link_to 'News', 'javascript:void(0);', 
  :onclick =&gt; "this.addClassName('youarehere');this.siblings().each(function(s){
  s.removeClassName('youarehere');});", :class =&gt; '', :id =&gt; 'news' %&gt; 
&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;     
Make sure you have a CSS class called &lt;span class="highlight"&gt;youarehere&lt;/span&gt;. The following CSS is just an example.
&lt;/p&gt;




&lt;div class="code"&gt;
&lt;pre&gt;
.youarehere {
    font-size: 11pt;
    text-decoration: underline;
}
&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;
If you are not using Ajax, you need to know what the current action and controller is. But how to know what the currect action is (without doing some ugly URL parsing)?
&lt;/p&gt;




&lt;p&gt;
The first thing to do is add the following code to your &lt;span class="highlight"&gt;application_helper.rb&lt;/span&gt; file
&lt;/p&gt;




&lt;div class="code"&gt;
&lt;pre&gt;
def section_link(name, options)
  action      = options[:action] || 'index'
  controller  = options[:controller] 
  
    if action == @current_action &amp;&amp; controller == @current_controller
      link_to(name, options, :class =&gt; 'youarehere')
    else
        link_to(name, options)
    end
end
&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;
The above method always expects an :controller key to be passed in with the options hash. If you don't pass the optional &lt;span class="highlight"&gt;:action&lt;/span&gt; key, it will assume 'index' as the action being performed.
&lt;/p&gt;




&lt;p&gt;
We need to know what the current_controller and current_action is for the above method to work. Finally put this in your &lt;span class="highlight"&gt;application_controller.rb&lt;/span&gt; file, as it makes the current executing action and controller name available to the helper.
&lt;/p&gt;




&lt;div class="code"&gt;
&lt;pre&gt;
before_filter :instantiate_controller_and_action_names

def instantiate_controller_and_action_names
    @current_action         = action_name
    @current_controller = controller_name
end
&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;In your view you have to use:&lt;/p&gt;




&lt;div class="code"&gt;
&lt;pre&gt;
&lt;%= section_link( "Home", :controller =&gt; 'welcome', :action =&gt; 'index' ) %&gt; |

&lt;%= section_link( "News", :controller =&gt; 'news', :ref =&gt; 'home' ) %&gt;
&lt;/pre&gt;
&lt;/div&gt;



&lt;img src="http://feeds.feedburner.com/~r/syedaslam/~4/_LEjgOPKNl0" height="1" width="1"/&gt;</content>
 		<feedburner:origLink>http://syedaslam.com/2011/03/28/highlight-current-link</feedburner:origLink></entry>
 	
 		<entry>
   			<title>Centering a Fixed-Sized Element</title>
   			<link href="http://feedproxy.google.com/~r/syedaslam/~3/dxzb_zfdRyY/centering-fixed-sized-elements" />
   			<updated>2011-03-22T00:00:00+05:30</updated>
   			<id>http://syedaslam.com/2011/03/22/centering-fixed-sized-elements</id>
   			<content type="html">&lt;p&gt;
  Here is one way to center a fixed-width/fixed-height div at the center of its container. This could be adapted to
  centering text, images, etc. within their containers. Essentially, we do a bit of arithmetic to get the fixed-sized
  element centered using absolute positioning and margins. Note that the parent container must have a 
  &lt;span class="highlight"&gt; position: relative &lt;/span&gt; property for this to work.
&lt;/p&gt;




&lt;div class="code"
&lt;pre&gt;
div {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 400px;
  height: 300px;
  margin-top: -150px; /* 1/2 of your element height*/
  margin-left: -200px; /* 1/2 of your element width */
}
&lt;/pre&gt;
&lt;/div&gt;

&lt;img src="http://feeds.feedburner.com/~r/syedaslam/~4/dxzb_zfdRyY" height="1" width="1"/&gt;</content>
 		<feedburner:origLink>http://syedaslam.com/2011/03/22/centering-fixed-sized-elements</feedburner:origLink></entry>
 	
 		<entry>
   			<title>Re-initializing table sequence in postgresql</title>
   			<link href="http://feedproxy.google.com/~r/syedaslam/~3/5werMYlTSCw/reinitialize-key-sequence-postgres" />
   			<updated>2011-03-15T00:00:00+05:30</updated>
   			<id>http://syedaslam.com/2011/03/15/reinitialize-key-sequence-postgres</id>
   			<content type="html">&lt;p&gt;
  Re-initializing a table sequence is quite normal and required in some cases. I had to do that recently. If the 
  table has data and needs to be preserved, then temporarily you have to move the data, delete the data in original
  table and re-initialize the sequence and copy the original data again. 
&lt;/p&gt;




&lt;p&gt; Use copy column names to reinitialize key sequence. &lt;/p&gt;




&lt;p&gt;
  In current versions of PostgreSQL you can specify column names with the COPY command to copy in or out only
  specific columns. This can come in handy if you want to recalculate your generated keys.
&lt;/p&gt;




&lt;p&gt; Given table: &lt;/p&gt;


&lt;div class="code"&gt;
  &lt;pre&gt;
    CREATE TABLE table_name (
        ID SERIAL PRIMARY KEY,
        name TEXT,
        role TEXT
    );
  &lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt; You can copy out only the name and the role like this: &lt;/p&gt;




&lt;div class="code"&gt;
  &lt;pre&gt;
      \COPY table_name (name, role) to 'something.dat'
  &lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt; And then you will want to delete your original data. &lt;/p&gt;




&lt;div class="code"&gt;
  &lt;pre&gt;
      DELETE FROM table_name;
  &lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;
  Then you can reset your sequence. Perhaps you found out later that you wanted to start the id field at 100 instead
  of 1. To restart your sequence and copy the data back in use:
&lt;/p&gt;




&lt;div class="code"&gt;
  &lt;pre&gt;
      ALTER SEQUENCE table_id_seq RESTART 100;
      \COPY people_131 (name, role) from 'something.dat'
  &lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;
  This technique can be used to copy in new data if the COPY formatted data does not have the generated key info in
  it. In that case, you would NOT alter the sequence or delete data from your original table.
&lt;/p&gt;




&lt;p&gt;
  You can achieve the same effect of the original example by selecting the data into a temporary table instead of
  copying out. After you copy the data into the temporary table, delete the original data, reset the sequence and
  copy it back in.
&lt;/p&gt;




&lt;div class="code"&gt;
  &lt;pre&gt;
      CREATE TEMPORARY TABLE people_temp AS SELECT name, role FROM people_131;
      ALTER SEQUENCE people_131_id_seq RESTART 1000;
      DELETE FROM people_131;
      INSERT INTO people_131 (name, role) select name, role from people_temp;
  &lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;
  Things to notice:
  
  &lt;ul class="prepend-1"&gt;
    &lt;li&gt; * The sequence name (if you need it) is table_column_seq. &lt;/li&gt;
    &lt;li&gt; * The format of the data to copy in must match the columns speficied. &lt;/li&gt;
  &lt;/ul&gt;
&lt;/p&gt;

&lt;img src="http://feeds.feedburner.com/~r/syedaslam/~4/5werMYlTSCw" height="1" width="1"/&gt;</content>
 		<feedburner:origLink>http://syedaslam.com/2011/03/15/reinitialize-key-sequence-postgres</feedburner:origLink></entry>
 	
 		<entry>
   			<title>Loading data from multiple files in Ruby using Hash</title>
   			<link href="http://feedproxy.google.com/~r/syedaslam/~3/YTd_HxQS10w/loading-data-from-multiple-files-at-once-using-ruby-hash" />
   			<updated>2011-02-19T00:00:00+05:30</updated>
   			<id>http://syedaslam.com/2011/02/19/loading-data-from-multiple-files-at-once-using-ruby-hash</id>
   			<content type="html">&lt;p&gt;
Lately, I have been working applications which require data from an external source to be loaded into the local database. One such application is Sydrea (in the making!), which requires the Drug information to be loaded. Drugs@FDA is freely downloadable compressed zip file which contains about 9 CSV files having Drug related data.
&lt;/p&gt;




&lt;p&gt;
The usual path to data loading is through a rails runner script. I was tired of writing, testing different scripts to load data. I had to come up with one general script which, with minimal customizations, could load data into whatever table. 
&lt;/p&gt;




&lt;p&gt;
I created the required models and tables. Database schema for the tables to hold drug related information is available at the Drugs@FDA website. I started with defining a Hash mapping the file containing data, to the Object.
&lt;/p&gt;




&lt;div class="code"&gt;
&lt;pre&gt;
files = {
    'AppDoc.txt'              =&gt; 'AppDoc',
    'AppDocType_Lookup.txt'   =&gt; 'AppDocTypeLookup',
    'application.txt'         =&gt; 'Application',
    'ChemTypeLookup.txt'      =&gt; 'ChemicalTypeLookup',
    'DocType_lookup.txt'      =&gt; 'DocTypeLookup',
    'product.txt'             =&gt; 'Product',
    'Product_tecode.txt'      =&gt; 'ProductTECode',
    'RegActionDate.txt'       =&gt; 'RegActionDate',
    'ReviewClass_Lookup.txt'  =&gt; 'ReviewClassLookup'
} 
&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;
What I need to do now is iterate over this hash, read file whose name is given by the &lt;code&gt;Key&lt;/code&gt; and create new objects of the type &lt;code&gt;Value&lt;/code&gt;. To the AR's &lt;code&gt;new&lt;/code&gt; method you can pass a hash with key names matching the associated table column names. The column names are given by the file headers. Now, I need a method which would take two arrays and return me a hash. Like given 
&lt;/p&gt;


&lt;p&gt;&lt;/p&gt;

&lt;div class="code"&gt;
&lt;pre&gt;
arr1 = ['col_name1', 'col_name2'] 
arr2 = ['val1', 'val2'] 
&lt;/pre&gt;
would return 
&lt;pre&gt;
{ 
    'col_name1' =&gt; 'val1',
    'col_name2' =&gt; 'val2'
}
&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;
I came up with a method that does exactly that and I added it to the Array class:
&lt;/p&gt;




&lt;div class="code"&gt;
&lt;pre&gt;
class Array
    def self.to_hash(headers, values) 
        hsh = Hash.new
        headers.each_with_index do |h, i|
            hsh[h.underscore] = values[i]
        end
    
        hsh
    end
end
&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt; Then, we're all set to put everything together and load data: &lt;/p&gt;




&lt;div class="code"&gt;
&lt;pre&gt;
require 'rubygems'
require 'fastercsv'

files.each do |key, value|
    file = "#{RAILS_ROOT}/db/drugsatfda/" + key
    recs = 0
    
    puts "Working with #{value.pluralize}.."
    FasterCSV.foreach(file, :headers =&gt; true) do |row|
        begin
            obj = value.constantize.new(Array.to_hash(row.headers, row.fields))
            obj.save
        
            recs += 1
        rescue =&gt; e
            puts "Rows processed: " + recs.to_s
            puts e
        end
    end
    puts "Loaded #{recs} #{value.pluralize}"
end
&lt;/pre&gt;
&lt;/div&gt;




&lt;div class="highlight alt"&gt; Technicals: Rails 2.3.8, PostgreSQL, FasterCSV &lt;/div&gt;

&lt;img src="http://feeds.feedburner.com/~r/syedaslam/~4/YTd_HxQS10w" height="1" width="1"/&gt;</content>
 		<feedburner:origLink>http://syedaslam.com/2011/02/19/loading-data-from-multiple-files-at-once-using-ruby-hash</feedburner:origLink></entry>
 	
 		<entry>
   			<title>Adding close link to flash messages</title>
   			<link href="http://feedproxy.google.com/~r/syedaslam/~3/7ejULAvcz2A/adding-close-flash-messages-rails" />
   			<updated>2011-01-24T00:00:00+05:30</updated>
   			<id>http://syedaslam.com/2011/01/24/adding-close-flash-messages-rails</id>
   			<content type="html">&lt;p&gt;
    The flash provides a way to pass temporary objects between actions. Anything
    you place in the flash will be exposed to the very next action and then 
    cleared out. This is a great way of doing notices and alerts, such as a 
    create action that sets flash[:notice] = "Successfully created" before 
    redirecting to a display action that can then expose the flash to its 
    template. Actually, that exposure is automatically done. But not closing or 
    removing and that flash message will be there till the view is refreshed or 
    a new action is served. 
&lt;/p&gt;




&lt;p class="center"&gt; &lt;img src='/images/flash-1.png' %&gt; &lt;/p&gt;




&lt;p&gt;
    In one of my recent applications I figured a way to add close link to make 
    flash message disappear. Of course, you can employ JavaScript to automatically hide 
    the flash div's after certain time. But, I choose to give an explicit close
    button / link. In my application template:
&lt;/p&gt;


&lt;div class="code"&gt;
&lt;pre&gt;
&lt;% flash.each do |name, msg| %&gt;
    &lt;%= content_tag :div, :id =&gt; "flash_#{name}" do %&gt;
        &lt;%= msg %&gt;
        &lt;%= content_tag :span, :style =&gt; "float: right;" do %&gt;
            &lt;%= link_to_function image_tag('icons/cross.png'), 
            :onclick =&gt; "document.getElementById('flash_#{name}').style.display='none'" %&gt;
        &lt;% end %&gt;
    &lt;% end %&gt;
&lt;% end %&gt;
&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt; A little styling: &lt;/p&gt;




&lt;div class="code"&gt;
&lt;pre&gt;
#flash_notice, #flash_error, #flash_alert {
    padding: 5px 8px;
    margin: 10px 0;
}

#flash_notice {
    background-color: #FAF0E6;
    border: solid 1px #5D871B;
    color: #5D871B;
}

#flash_error, #flash_alert {
    background-color: #FAF0E6;
    border: solid 1px #5D871B;
    color: #5D871B;
}
&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;
    You need to have a image 'cross.png' in your 'images/icons'. And the 
    outcome of is:
&lt;/p&gt;




&lt;p class="center"&gt; &lt;img src='/images/flash-2.png' %&gt; &lt;/p&gt;

&lt;img src="http://feeds.feedburner.com/~r/syedaslam/~4/7ejULAvcz2A" height="1" width="1"/&gt;</content>
 		<feedburner:origLink>http://syedaslam.com/2011/01/24/adding-close-flash-messages-rails</feedburner:origLink></entry>
 	
 		<entry>
   			<title>Connecting to two or more databases from a Rails app</title>
   			<link href="http://feedproxy.google.com/~r/syedaslam/~3/AxjELVfJH2Q/connecting-two-databases" />
   			<updated>2011-01-18T00:00:00+05:30</updated>
   			<id>http://syedaslam.com/2011/01/18/connecting-two-databases</id>
   			<content type="html">&lt;p&gt;
    The current project I am working on is a re-write of an old application, 
    which essentially was build as an prototype. At that time it was put off 
    due to reasons unknown and now the client has come back for the same 
    application with a new set of requirements and changes to the prototype. 
&lt;/p&gt;




&lt;p&gt;
    Its a spatial application where everything is centered around 'location' 
    and location information (pincodes etc.,). In the prototype application 
    Location information is stored is stored in 'pinlocations' table. It takes 
    a lot of effort to fill this table with lat, lng and other inforation and I 
    didn't want to repeat it and the schema didn't change as much for this 
    table. So, I decided to populate my new tables from the data in this table.
&lt;/p&gt;




&lt;p&gt;
    There are plugins (&lt;a href="http://github.com/cherring/connection_ninja/" 
    target="_blank"&gt;connection_ninja&lt;/a&gt;, &lt;a href="https://github.com/karledurante/secondbase"
    target="_blank"&gt;secondbase&lt;/a&gt;, 
    &lt;a href="https://github.com/tchandy/octopus" target="_blank"&gt;octopus&lt;/a&gt;) 
    available which provide ways to connect to two (or more) databases from a 
    rails application. But, my case was simple (one table) which I could do 
    neatly and easily without a gem overkill.   
&lt;/p&gt;




&lt;p&gt;
    I had to define temporary models in the application to work with the old 
    database and employ the '&lt;a href="http://api.rubyonrails.org/classes/ActiveRecord/Base.html#method-c-establish_connection" target="_blank"&gt;
    establish_connection&lt;/a&gt;' method of the &lt;a href="http://api.rubyonrails.org/classes/ActiveRecord/Base.html" target="_blank"&gt;ActiveRecord::Base&lt;/a&gt;. 
    This method accepts a hash as input through which you provide the 
    connection information.
&lt;/p&gt;




&lt;div class="code"&gt;
&lt;pre&gt;
class Pinlocation &lt; ActiveRecord::Base
    establish_connection(
        :adapter  =&gt; "postgresql",
        :host       =&gt; "localhost",
        :username =&gt; "*****",
        :password =&gt; "*****",
        :database =&gt; "old_database"
    )
end
&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt; You can check whether the connection is established in the rails console: &lt;/p&gt;




&lt;div class="code"&gt; &lt;pre&gt; $&gt; location = Pinlocation.first &lt;/pre&gt; &lt;/div&gt;




&lt;p&gt; This loads the first record from the "old_database" connection. &lt;/p&gt;




&lt;p&gt; Then a script to read data from the old database and write to new database. &lt;/p&gt;




&lt;div class="code"&gt;
&lt;pre&gt;
require 'rubygems'

out_file = "db/data/scripts/output.txt"
# I like the output (messages, errors ets.,) to be written to a file 
instead of the console.

open(out_file, 'w') do |f|
    f.puts "Total no. of record to be imported: #{Pinlocation.count}"

    ...

    Pinlocation.all.each do |location_old| 
        begin
            location_new = PinLocation.new(
                :pincode    =&gt; location_old.pincode,
                :name       =&gt; location_old.name,
                :lat            =&gt; location_old.lat,
                :lng            =&gt; location_old.lng
            )

            # Then I map the district, state to this location
            ...

            location_new.save

        rescue ActiveRecord::RecordInvalid =&gt; invalid
            puts invalid.record.errors
            f.puts invalid.record.errors
        end
    end
end
&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt; And I am set. &lt;/p&gt;

&lt;img src="http://feeds.feedburner.com/~r/syedaslam/~4/AxjELVfJH2Q" height="1" width="1"/&gt;</content>
 		<feedburner:origLink>http://syedaslam.com/2011/01/18/connecting-two-databases</feedburner:origLink></entry>
 	
 		<entry>
   			<title>syedaslam.com version 3!</title>
   			<link href="http://feedproxy.google.com/~r/syedaslam/~3/wbqmnrmLyJo/syedaslamcom-version-3" />
   			<updated>2011-01-15T00:00:00+05:30</updated>
   			<id>http://syedaslam.com/2011/01/15/syedaslamcom-version-3</id>
   			<content type="html">&lt;h3&gt; So, what is this brand new blog gonna be about? &lt;/h3&gt;




&lt;p&gt;
    Well, first of all, I'd like to introduce myself. My name is Syed Aslam. I'm from Bangalore, India.
    I've been working in the web industry for quite some time now, so this blog will probably be about new (and old)
    web technologies, search engine secrets, web design tips and tricks (and many many more, hopefully).
&lt;/p&gt;




&lt;p&gt;
  This blog will be my notepad for my crazy experiments in the software development world. This will serve not only to
  know where I currently stand or where I'm headed, but also to know where I've been. 
&lt;/p&gt;




&lt;p&gt;
    Oh, and I'd like to say thanks to the Jekyll for making blogging geeky and fun and Heroku for this wonderful 
    (and free!) platform. It looks great and it's handy-coded, so I'll be sure to customize it in a while. 
&lt;/p&gt;




&lt;p&gt; So, subscribe to my feed and stay tuned! &lt;/p&gt;

&lt;img src="http://feeds.feedburner.com/~r/syedaslam/~4/wbqmnrmLyJo" height="1" width="1"/&gt;</content>
 		<feedburner:origLink>http://syedaslam.com/2011/01/15/syedaslamcom-version-3</feedburner:origLink></entry>
 	
</feed>

