A funny but scary problem

Now this is funny and scary at the same time. I ran into a problem which well, most of you(actually even me would term as stupid). This post is however not to show display my stupidity but something else.

Here is a snippet of code for taking an user input.

<p>Register if you wish to receive updates about the broadcast.</p>

<input type="text" id="email_address" />

<input type="submit" value="SUBMIT" class="submitBt" onclick="register();" />

Now what this piece of code does is, take an input (email) from the user and when the user clicks on the user a register() function is called which takes the email and sends it to the database.

function register() {

var email_address = document.getElementById("email_address").value;


url: '',

type: 'POST',

data: {

query: data_


success: function(data)


window.location = "";



Now what was the problem with this code. I tried to figure it out for like 4-5 hours. Very simple javascript, nothing wrong with it. Takes the data that the user types in the input area and the register() function is called when the button is clicked. Stuff that was bothering me more was, it was working perfectly in firefoz but not in chrome. why? WHY? WHYYY??

So you see, what I am doing here is –

1. On the click of the button, I am submitting the form as well as calling the javascript function.

2. Now well, since I haven’t given any action method, so where is it going to submit, ofcourse to the same page, duh!

3. So firefox called the register() function first, which in turn changed the window.location to our tq.html page, but chrome just called the ajax function and submitted the page, so it just reloaded.

Well! I was looking too hard at the javascript and not at the html code. Had I looked at the HTML, I might have found the problem soon. Small things in life that make you smile and small coding horror like this can make you wanna break your keyboard 🙂


Choose the db adapter while creating a new application in rails

A lot of people are moving towards Ruby on Rails even at corporate level and giving up the standard Java, .Net way of developing websites for their customers. There are plenty of reasons for that, one of them being their argument that these languages are good at small level but are not scalable enough to solve the needs of corporate level customers. But now even developers who have been coding in java or other languages are increasing looking at solving their problems using frameworks such as Rails or Python/Django.  I believe the development curve of any language is steep only because of the time you want to devote to that language. I chose to devote some time to learn a few things in rails that makes life easy or atleast saves a bit of time. So lets see. lets make some rails stuff.

You would know that to create a new application all you need to do is type

rails new application_name

But this configures the application to use the sqlite3 database, If you want to use any other database, you would have to change it manually in the config->database.yml file. But there is a better way to do it, If you are sure, what database you are going to use, you can just specify it at the time to creating the application

rails new application_name -d mysql

The “-d” specifies the database name, you can use any of the databases from the list – mysql, oracle, postgresql, sqlite3, frontbase, ibm_db, sqlserver, jdbcmysql, jdbcsqlite3, jdbcpostgresql, jdbc.

No Ruby Version Manager on Windows.

Its true that there is no ruby version manager on windows, which makes life really difficult for a lot of ruby or rails developers I am sure, Well it did for me at least. A lot of applications developed in version 1.8.7 aren’t compatible with the new version. A lot of applications also fix themselves to use only specific versions of ruby, so there is not much we can do, unless you are a mega-geek and can change a lot of things and ofcourse have a lot of time. On linux we always have had RVM to solve this problem which lets us have different versions of ruby, different gemsets for each version of ruby, makes life really easy. But what for the windows developers? Thankfully a noble soul known as Gordon Thiesfeld made something amazing known as pik. which essentially works the same as Ruby version manager, with a few differences in installations but none in usage. Both of them are equally easy to use.

I am not going to write about how to install and use RVM, since there is enough help for that on the WWW. But Since I love windows users(I being one). We will have a walk-through with pik today. Before we start you can have a look at the github page of the project – https://github.com/vertiginous/pik

Installations –

It does mention that you need to install ruby 1.8.7 first to install pik, Now ruby 1.8.7 is an older version and I wonder, why would I need to install an older version to install a newer version, So first I went ahead and installed ruby 1.9.2-p290 from http://rubyinstaller.org/downloads/ for installing pik. Seems it worked just fine. You can choose to install ruby 1.8.7 first and then install pik, its entirely upto you.

After installing Ruby make sure, you also have devkit installed, if you are a windows user you would know that ofcourse, dev kit is used to build the gems that are developed with native extensions, which means nothing, but those gems are made partially in ruby and partially using c. You can’t miss C anywhere can you. Anyways, I will give a quick guide about installing devkit, since you are going to need it anyways.

Head over to http://rubyinstaller.org/downloads/ and download DevKit.
Installations steps
1. The file you downloaded is just an extractor, extract is to somewhere where you wont delete it by mistake.
2. After extraction, open up CMD and cd to the location where you extracted the files.
3. run

ruby dk.rb init

4. This will let you know the ruby installed in your system.
5. run

ruby dk.rb install

and you are done. Didn’t take too much time, did it?

Now we move on to pik installation steps
1. Fire up CMD and run

gem install pik

2. Now if you type

pik list

you will be able to see that it shows the base version of ruby that you installed. In my case, it shows

* 192: ruby 1.9.2p290 (2011-07-09) [i386-mingw32]

3. There are two ways of adding ruby versions to pik, either you install them manually and add to pik or you just install them through pik. We will see how to install them from pik, since we are going to use pik anyway, less bothersome to do it from pik, than downloading from the internet, installing each of them and then adding to pik.
4. Installing other version of ruby

pik install ruby 1.8.7

And here you go it will install the version of ruby and add that to pik by itself, Less of a hassle. right?
5. Check the versions of ruby installed in your system

pik list

6. Change the version of ruby that you want to use

pik use ruby [verions]

in my case

pik use ruby 1.8.7

7. Don’t forget to use the help if you get stuck.

pik help commands