Friday, October 19, 2012

Rename a database column in Rails using migration

There are times when you need to rename a database table's column name in Rails which was originally created by using scaffold/generate command. To do so first create a new empty migration and then add following statement in self.up
rename_column :table, :old_column, :new_column
Visit this question for detail description (with complete code) Rename a database column in a migration

Sunday, October 14, 2012

Installing and running MySQL service on windows

It may occur that while installing a fresh copy of MySQL server, the mysql service does not start automatically. In-fact, service is not added/installed to windows by default. In that case follow the following steps:
I'm assuming that MySQL server is installed. If not then go to MySQL download link and download Windows (x86, 32-bit), MSI Installer

a) First of all change User Account Control (UAC) settings to allow installation of new service to windows. Go to control panel > User Account, then open 'Change User Account Control settings'. Change settings from default to lowest i.e. Never Notify. Hit OK and restart system to apply changes.

b) After restart, open command prompt and navigate to bin directory of MySQL. It might be in ProgramFiles or ProgramFiles(x86). Here is the path of this on my machine: C:\Program Files (x86)\MySQL\MySQL Server 5.5\bin.
$ cd C:\Program Files (x86)\MySQL\MySQL Server 5.5\bin
 then install mysql service using:
$ mysqld --install
Careful - there is 'd' in service name. After installation, you can verify whether service is properly installed or not in services list. (Run services.msc command in run prompt not cmd).

Now just start the service by using (in cmd):
$ net start mysql
That's all. Your MySQL service is up.

Monday, October 8, 2012

Maintaining multiple ruby and ruby gems version in windows

I've two different gem repository 1.8.7 and 1.9.1. However ruby gem environment uses only one gem repository for all uninstall and update commands (which can be retrieved using GEM ENV) command. But because of this I was somewhat helpless for uninstalling/modifying the gems in repository different from the default one. Use the following steps to control the same:

Maintaining multiple ruby version: PiK is a very helpful gem to maintain multiple ruby versions on your machine. You can add references of all ruby versions available in system and select which one to use by default i.e. updating Gem environment.
a) Install Pik gem: Open command prompt with ruby and rails (type ruby in search box on windows)
gem install pik
b)  Then add the bin path of all ruby versions available like:
pik add C:\RailsInstallerNew\Ruby1.9.3\bin
 c) Now run "$ pik list" command to verify all ruby versions added to pik. Also notice there will be a unique number in the starting of each ruby instance like 187, 193 (which references the ruby versions).

d) To select a particular ruby version use "pik <unique number mentioned in point c>" like
pik 187
After this command if you fire pik list command then you'll see a * in front of ruby 187 version. Also "$ gem env" command will show ruby version 1.8.7 as the default version selected.

Maintaining multiple gem set with multiple ruby versions (not sure): In case of multiple gem directory and uninstalling a particular gem version (from the gemset different from the default gem repository) first go to the gem bin directory of that particular ruby version (from the cmd) and then fire run "gem uninstall <gemname>".

Sunday, October 7, 2012

Invalid date format specification in gemspec

If someone is facing issue with gems version conflict or have an error like "Error running test: units and test: functional" while running bundle exec rake command then following steps might fix all gems version conflict related issues like "Invalid date format specification in gemspec"

Go to your project directory in CMD and run following commands:
1. "gem install rubygems-update",
2. "update_rubygems",
3. then "gem pristine --all"

This combination solved the problem for me.

The program can't start because LibMySQL.dll is missing from your computer.

Follow these steps to fix this issue:
Step -1 copy the libmySQL.dll from this link LibMySQL.dll download link (Assuming you're using ruby 1.8 not 1.9, in case if you are using the latest version then take the latest dll version not this one which you can retrieve by installing the latest mysql exe on your machine and this dll can be found at: C:\Program Files (x86)\MySQL\MySQL Server 5.5\lib)
Step -2 Paste it in C:\Ruby\bin of yours