Wednesday, July 27, 2011

renaming a database column using rails generate migration

To rename a database column using rails generate migration command:
1. run "rails generate migration 'RenameDatabaseColumn'"
2. This will create a database migration file in db/migrate/20110727115656_rename_database_column

class RenameDatabaseColumn < ActiveRecord::Migration
def self.up
rename_column :table, :old_column, :new_column
end

def self.down
rename_column :table, :new_column, :old_column
end
end

3. Then just run "rake db:migrate" to rename the column
4. To roll back just run "rake db:rollback"

Tuesday, June 21, 2011

Online JSON viewer

A really nice online JSON viewer with a tree like structure:
Online JSON viewer: http://jsonviewer.stack.hu/

Sunday, June 19, 2011

GIT refusing to update checked out branch: refs/heads/master

To solve this issue below, simply execute this in your master repository:

"git init --bare"

The shared repository has to be a bare repository before your can push into it.

Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 296 bytes, done.
Total 3 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
remote: error: refusing to update checked out branch:
 refs/heads/master
remote: error: By default, updating the current branch 
in a non-bare repository
remote: error: is denied, because it will make the index 
and work tree inconsistent
remote: error: with what you pushed, and will require 
'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error: 
remote: error: You can set 'receive.denyCurrentBranch' 
configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository
 to allow pushing into
remote: error: its current branch; however, this is not 
recommended unless you
remote: error: arranged to update its work tree to match 
what you pushed in some
remote: error: other way.
remote: error: 
remote: error: To squelch this message and still keep the 
default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration
 variable to 'refuse'.

Testing JS popup box using selenium webdriver

To simulate the user clicking the ok or cancel button for a javascript pop up box simply use the following selenium web driver methods into your steps defintion:

<pre>
page.driver.browser.switch_to.alert.accept #to click ok
page.driver.browser.switch_to.alert.dismiss
</pre>

Wednesday, June 15, 2011

no such file to load require_relative (MissingSourceFile)

This error was introduced when I gem install ruby-debug (June 2011) and Ruby-debug install linecache gem 0.45 by default. Linecache 0.45 causes this "no such file to load require_relative (MissingSourceFile)". To fix this is to downgrade linecache to the earlier version such as 0.43

Could not find generator cucumber:install

>$ rails generate cucumber:install --capybara
Could not find generator cucumber:install.

I fix this by installing cucumber-rails gem instead of the cucumber gem.

gem install cucumber-rails
or you can put it in your bundle file.

source 'http://rubygems.org'
.
.
.
group :test do
  gem 'rspec', '2.5.0'
  gem 'capybara'
  gem 'cucumber-rails'
end

rails generate cucumber:install --capybara

create config/cucumber.yml
create script/cucumber
chmod script/cucumber
create features/step_definitions
create features/step_definitions/web_steps.rb
create features/support
create features/support/paths.rb
create features/support/selectors.rb
create features/support/env.rb
exist lib/tasks
create lib/tasks/cucumber.rake
gsub config/database.yml
gsub config/database.yml
force config/database.yml

Thursday, April 14, 2011

E: Unable to locate package - apt-get install error

test@test-Veriton-S661:~$ sudo apt-get install git
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package git

To fix this, you probably just need to update the apt-get list.


test@test-Veriton-S661:~$ sudo apt-get update
Get:1 http://au.archive.ubuntu.com maverick Release.gpg [198B]
Ign http://au.archive.ubuntu.com/ubuntu/ maverick/main Translation-en
Get:2 http://au.archive.ubuntu.com/ubuntu/ maverick/main Translation-en_AU [1,813B]
Ign http://au.archive.ubuntu.com/ubuntu/ maverick/multiverse Translation-en
.
.
.

Then run the 'apt-get install' again to install the package that you want.

Tuesday, March 1, 2011

Ubuntu default root password

So what is the ubuntu default root password? I have just installed Ubuntu 10.10 and during the installation process it did not ask for the root password.

After the installation is finished, I try to login as a root using the "su" command. However, when it asked for the password, I could not login. There is no default/empty password for root.

It turns out you need to set the root password first by using this command:


sudo passwd
Enter new UNIX password:
Retype new UNIX password:


You can also login as a root without setting the password by using this command:

sudo su

Monday, February 28, 2011

Could not open library 'xml2' 'libxml2.so'


Could not open library 'xml2' : xml2:
cannot open shared object file: No such file or directory.
Could not open library 'libxml2.so' :
libxml2.so: cannot open shared object file: No such file or directory
(LoadError)


To fix the issue, please run the following command:


sudo apt-get install ruby1.8-dev
sudo apt-get install libxml2 libxml2-dev libxslt1-dev

Unable to locate tools.jar. Expected to find it in /usr/lib/jvm/java-6-openjdk/lib/tools.jar

When running my 'ant' script I get the following error:


Unable to locate tools.jar.
Expected to find it in /usr/lib/jvm/java-6-openjdk/lib/tools.jar


To solve it, I need to install java-sdk:


sudo apt-get install openjdk-6-jdk

Thursday, February 10, 2011

Only one usage of each socket address (protocol/network address/port) is normally permitted. : make_sock: could not bind to address 0.0.0.0:80

This is my first time trying to install an Apache server on my Windows XP machine. Previously I was using IIS. I installed Apache 2.2 and was using the self installation program provided by Apache.

Upon installing Apache, I immediately received the following errors;


The Apache service named reported the following error:
(OS 10048)Only one usage of each socket address
(protocol/network address/port) is normally permitted.
: make_sock: could not bind to address 0.0.0.0:80 .





It seems that the error was saying that there was a conflict in using the port 80. My natural response was to stop my windows firewall. However, it did not work. I was finally able to figure out the issue and it was because I was still running IIS on my Windows machine and therefore there was a conflict between Apache and IIS server.

I uninstalled IIS and I can immediately start Apache server with no problems.